Yesterday When I was trying to connect to Microsoft SQL Server database, I got an error like this – Cannot open user default database. Login failed. Login failed for user. (Microsoft SQL Server,error:4064). I did not made any changes in configuration or settings of SQL server, but still was not able to open SQL server databases due to this error. This error shows up due to some deleted database which was mapped as default database to my username. When you try to access that default database, the SQL server does not able find that database.
The solution of this problem is very simple. You need to set master as your default database. Here is how to do it:
Cannot open user default database. Login failed. – Fix
- Click on the Options button in the Connect to Server window.
- Under the Connection Properties tab, Change the Connect to database value from <default> to master.
- Click on the Connect button and now you should be able to successfully log in.
- After log in, you need to perform one more step to get rid of this error permanently. Type the following statement and hit F5 to run. Make sure to replace test with your Username and master with your database name(that you want to set as new default).
ALTER LOGIN [test] WITH DEFAULT_DATABASE = master
If you have made the above two replacements correctly, you should see a message – Command completed successfully.
Whether this solution worked for you or not, let me know in comment section.