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)
The fix for this problem is very simple.
Fix/Workaround/Solution:
First click on Option>> Button of “Connect to Server” Prompt.
Now change the connect to database to any existing database on your server like master or msdb.
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
Watch SQL in Sixty Seconds video to Resolve Connection Error:
[youtube=http://www.youtube.com/watch?v=1k00z82u4OI]
Reference : Pinal Dave (http://www.SQLAuthority.com)
282 Comments. Leave new
11 year old post… still saves the day. Great work, Pinal!
THANK YOU! I very briefly detached a prod DB w/out a change record and couldnt reconnect to attach – this fix bailed me
Very helpful thanks.
Thank you so much,
thanksssss, save me hahaha
Really worked!..thanks alot
It doesn’t work for me because I couldn’t find master in the drop-down of Connect to database. Any solution?
type the master database manually. Today i face same issue and fixed it. I also type manually master (Database)
Thanks for your help. Today i face same issue and fix it as per your articles.
Thank you so much. Your solutions are helping me a lot.
It works!
Its excellent solution. Its a one place where we can find solutions for all our issues.
You rock! Can’t tell you how many times you’ve been of help.
Thank you
YOU ARE THE MAN! Whenever I see sqlauthority come up in the Google search results, I know my problem is about to be fixed! All I have to do is read. Thank you so much!
Thank you. This fixed my problem.
Thank you so much Pinal
Thank You so much.
Thank you. Dropped a database and unable to login afterwards. This fixed the problem.
I was tearing my hair out – could have been a real problem. Thank you!
Thank you so much!