I've made a copy of my database (which is on Azure) on local SQLExpress server. On this server I have user "Tester" that has db_owner
role for that database.
I can easily connect to it using Microsoft SQL Server Management Studio using server name: (LocalDb)MSSQLLocalDB
, SQL Server Authentication and "Tester" user credentials. but when I connect to it in my code with connection string like:
const string ConnectionString =
"Server=(LocalDb)\MSSQLLocalDB;" +
"Initial Catalog=Integration-Tests;" +
"Persist Security Info=False;" +
"User ID=Tester;" +
"Password=secretPassword;" +
"MultipleActiveResultSets=False;" +
"Encrypt=True;" +
"TrustServerCertificate=False;" +
"Connection Timeout=30;";
using (var connection = new SqlConnection(ConnectionString))
{
try
{
connection.Open(); // Exception thrown
/* some more code that doesn't matter */
}
finally
{
connection.Close();
}
}
I get following exception thrown:
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: Named Pipes Provider, error: 0 - No process is on the other end of the pipe.)
Earlier I was getting something else, but I guess it could be a simple typo since it stopped happening, I'm including it just in case it helps:
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: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist.
As stated earlier, everything works fine both on Azure, and I can connect to my LocalDb through SSMS.
Does anyone have any idea what could be cause of this error?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…