Fixing: SQL Server Error 4064 …
An error that is known how to solve it, I was the victim today with it and when I started the SSMS, I saw that error. I’m telling you here how to fix it as fast info and references from MS.
This error usually comes when your DB no longer exists or it is in suspect mode or has been detached or offline etc, and you will have the pop-up message with error description and the number 4064:
Ok, as you can see the user Blue cannot connect in the default database and the login failed!
Fixing this error is really easy, so you can try again to login with that user but first before to Connect, you must go to the Options that is in right corner below and you will be asked for the Connection Properties on the second tab of the login dialog box and you must enter the master database in the drop-down box, see the fig below and hit Connect:
Now you will be able to connect in your SQL Server. So what’s next!? As I said, some of the reason why it happened are described above, so now you can check for the correct DB that must be as default DB of that user. After that to be sure for the next connection you need to change the default DB via T-SQL or GUI:
GUI: Open the SSMS on the right, you have object Explorer, go to Security > Logins > Find your login and right click > Properties. You will have the dialog box like shown in the fig below.
Or you can use the T-SQL script:
ALTER LOGIN [Blue] WITH DEFAULT_DATABASE=[TESTING2];
For more info about this error, you can check here.