Cannot connect to (LocalDB)\MSSQLLocalDB -> Login failed for user 'User-PC\User'

SqlSql ServerSsmsLocaldb

Sql Problem Overview


I am getting an error, While I am trying to connect (LocalDB)\MSSQLLocalDB through SQL Server management studio. I also tried to login with default database as master the error is same.

enter image description here Here is the Server details. enter image description here

Sql Solutions


Solution 1 - Sql

The following command through sqllocaldb utility works for me.

sqllocaldb stop mssqllocaldb
sqllocaldb delete mssqllocaldb
sqllocaldb start "MSSQLLocalDB"

enter image description here

After that I restarted the sql server management studio, and it is successfully established connection through (LocalDB)\MSSQLLocalDB

Solution 2 - Sql

For this particular error, what gave me access to my MDF in VS2019 was:

  1. In Solution Explorer, right click your MDF file
  2. Detach

That was it and I now have access. I was expecting to detach and attach, but that wasn't needed.

I also could not get to my (localdb) in SSMS either, so what helped me there was a solution by Leniel Maccaferri. Here is the link to his site, along with the excerpt that helped me:

https://www.leniel.net/2014/02/localdb-sqlserver-2012-cannot-open-database-requested-by-login-the-login-failed-error-4060.html

enter image description here

So guess what: the solution is ridiculously easy once you know what to do of course…

Click that Options >> button in Figure 1. Now select the Connection Properties tab.

SSMS Connect to Server | Connection Properties | Connect to database optionFigure 2 - SSMS Connect to Server | Connection Properties | Connect to database option

I had to type master in Connect to database field since I did not have it in the list of available databases.

Now click connect and you’re done.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMusakkhir SayyedView Question on Stackoverflow
Solution 1 - SqlMusakkhir SayyedView Answer on Stackoverflow
Solution 2 - SqlJames LeeView Answer on Stackoverflow