Why does this work to connect to my remote SQL Server database:
var srvConn = new ServerConnection("sql01"); srvConn.LoginSecure = false; srvConn.Login = "unittests"; srvConn.Password = "mypwd"; srvConn.DatabaseName = "MediaFilesDb"; var srv1 = new Server(srvConn); Console.WriteLine(srv1.Information.Version);
And this does not work:
var scsb = new SqlConnectionStringBuilder(); scsb.DataSource = "sql01"; scsb.InitialCatalog = "MediaFilesDb"; scsb.IntegratedSecurity = false; scsb.UserID = "unittests"; scsb.Password = "mypwd"; var srv1 = new Server(scsb.ConnectionString); Console.WriteLine(srv1.Information.Version);
I get the infamous error 40:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
If I take the connection string that is being generated and paste it into another tool, such as CodeSmith, it works correctly and the connection is established.
Why does the second example fail?
If I specify TCP/IP for the network library:
scsb.NetworkLibrary = "dbmssocn";
I get this error:
The value's length for key 'data source' exceeds it's limit of '128'.
This is my connection string:
Data Source=sql01;Initial Catalog=MediaFilesDb;Integrated Security=False;User ID=unittests;Password=**;Pooling=False;Network Library=dbmssocn;