Cannot connect to LocalDB (provider: Named Pipes Provider, error: 0 - No process is at the other end of the pipe)

AxD 671 Reputation points
2024-09-24T22:22:06.79+00:00

I'm trying to manually connect to LocalDB (both, SQL Server 2019 and SQL Server 2022 services) creating a new application database using ADO.NET (Microsoft.Data.SqlClient).

Everytime I try to connect, I get a generic error telling me that the database file could not be attached.

Error.log:

2024-09-17 19:30:18.40 Logon       Error: 15350, Severity: 16, State: 1.
2024-09-17 19:30:18.40 Logon       An attempt to attach an auto-named database for file C:\Temp\CvTest.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
2024-09-17 19:31:02.66 Logon       Error: 15350, Severity: 16, State: 1.
2024-09-17 19:31:02.66 Logon       An attempt to attach an auto-named database for file C:\Temp\CvTest.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Debugging into the Microsoft.Data.SqlClient source code, the following error turned out to be the real reason behind the issue:

A connection to the server could be established, but an error occurred during the
login process. (provider: Named Pipes Provider, error: 0 - No process is at the
other end of the pipe).

What is causing this error?

This is my simple test connection setup. It's a cheap connection string that every Microsoft sample is quoting:

using SqlConnection con = new SqlConnection(@"Data Source=(LocalDb)\MSSQLLocalDB;Integrated Security=SSPI;MultipleActiveResultSets=True;AttachDBFilename=C:\Temp\CvTest.mdf");

con.Open();

So, it should work off the cuff. But it doesn't.

Using SSMS, I can easily connect to the LocalDB instance and create/delete databases promptly, even with the provided path.

I already updated from MsLocalDb 15 to MsLocalDb 16, but to no avail.

SQL Server | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. ZoeHui-MSFT 41,496 Reputation points
    2024-09-25T01:59:01.35+00:00

    Hi @AxD,

    • Make sure Named Pipe is enabled in configuration manager (don't forget to restart the server).
    • Make sure the database you are connecting to exists.
    • Make sure SQL Server Authentication (or Mixed Mode) is enabled.
    1. Right Click the Server in SSMS and pull up server properties
    2. Go to Security--> Select 'SQL Server and Windows Authentication Mode'
    3. Restart the Server and Login with the credentials

    Regards,

    Zoe Hui


    If the answer is helpful, please click "Accept Answer" and upvote it.

    0 comments No comments

  2. Erland Sommarskog 122.4K Reputation points MVP Volunteer Moderator
    2024-09-25T21:38:44.9966667+00:00

    In your connection string, you have the option AttachDBFilename. This option is highly dubious in my opinion. I have never understood the point with it.

    From the error message, I would guess that you already have a database CvTest, with the files located somewhere else.

    Connect to (localdb)\MSSQLLOCALDB with SSMS and see which databases you have. If there is a CvTest, drop it or rename it. Or just stop using AttachDBFilename.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.