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

56,758

Solution 1

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

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.

Share:
56,758
Musakkhir Sayyed
Author by

Musakkhir Sayyed

Apparently, this user prefers to keep an air of mystery about them.

Updated on July 09, 2022

Comments

  • Musakkhir Sayyed
    Musakkhir Sayyed almost 2 years

    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