Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
331 views
in Technique[技术] by (71.8m points)

c# - LocalDb "No process on the end of the pipe"

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I've found the answer, posting it for anyone who ever has same problem:

I realized there was no verifiable server certificate, and according to Microsoft documentation, with Encrypt=true in my connection string:

Encryption occurs only if there is a verifiable server certificate, otherwise the connection attempt fails.

Indeed, the error code could be a little more descriptive... but all I had to do, was to remove Encrypt part from connection string.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...