1
votes

Using SQL Server 2016 (localdb)\ProjectsV13, I created a database - let's call it MyDatabase. All was fine and dandy until I decided I no longer needed it...

So in SSMS 2016, while connected to (localdb)\ProjectsV13, I right clicked on MyDatabase and clicked "Delete".

Now when I try to establish a connection to (localdb)\ProjectsV13, it fails.

Here's the error message:

Cannot connect to (localdb)\ProjectsV13.

Cannot open database "MyDatabase" requested by the login. The login failed. Login failed for user 'MyDomain\MyUserName'. (Microsoft SQL Server, Error: 4060)

So even though I deleted the MyDatabase database (I know - I should of just run a DROP), SSMS is still trying to connect to MyDatabase which of course fails and then prevents me from connecting to (localdb)\ProjectsV13 at all - which is the real issue.

How can I resolve this so that SSMS doesn't try to connect to the deleted MyDatabase database when connecting to (localdb)\ProjectsV13?

1
What is the default database for your user?Sean Lange

1 Answers

1
votes

Like Sean suggested, I think your default database is the problem. If you're using visual studio, right-click the server and click on the properties option. You'd see a 'Default Database Location' property. Alter the value. If you're not using visual studio, then change your default database or check that your connection string does not attach the deleted database when you connect. E.g.

connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\StaffLoginSystem.mdf;Integrated Security=True;Connect Timeout=30"

Check the value of 'AttachDbFilename' property and edit accordingly.