SQL SERVER – Fix : Error: 4064 – Cannot open user default database. Login failed. Login failed for user

I have received following question nearly 10 times in last week though emails. Many users have received following error while connecting to the database. This error happens when database is dropped for which is default for some of the database user. When user try to login and their default database is dropped following error shows up.

Cannot open user default database. Login failed.
Login failed for user ‘UserName’. (Microsoft SQL Server, Error: 4064)

SQL SERVER - Fix : Error: 4064 - Cannot open user default database. Login failed. Login failed for user error4064

The fix for this problem is very simple.

Fix/Workaround/Solution:

First click on Option>> Button of “Connect to Server” Prompt.

SQL SERVER - Fix : Error: 4064 - Cannot open user default database. Login failed. Login failed for user error4064_1

Now change the connect to database to any existing database on your server like master or msdb.

SQL SERVER - Fix : Error: 4064 - Cannot open user default database. Login failed. Login failed for user error4064_2

Now click on connect and it will successfully log you in. Once you login in the system run following statement for your username and it should fix your problem. Make sure to replace [test] with your username and master with yourdatabase name.

ALTER LOGIN [test] WITH DEFAULT_DATABASE = master
GO

SQL SERVER - Fix : Error: 4064 - Cannot open user default database. Login failed. Login failed for user error4064_3

Watch SQL in Sixty Seconds video to Resolve Connection Error:

Reference : Pinal Dave (http://www.SQLAuthority.com)

,
Previous Post
SQLAuthority News – SQL Server Security Whitepapers
Next Post
SQL SERVER – Clear Drop Down List of Recent Connection From SQL Server Management Studio

Related Posts

280 Comments. Leave new

Leave a Reply