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
Thank you very much, it’s really quite simple when you know.
easy and useful. thank you. it helped a lot
Thanks A Lot Sir. You made my life easy :).
thank you very much, your solution solved the problem
best regards
Working since 2008. Thanks.
very useful
This fix worked for me. Thanks!
thanks for your tip, it was very useful!
Dave, I can’t thank you enough. I make a lot of mistakes as a Jr. Dev and setting my default db to one that was later removed really messed me up. This worked like a charm.
Thank you for your share solution that it helps me fix issue faster.
I used this method to get back into my server, Thanks. However, now everything is running slower than molasses uphill. Any ideas?
Great. It worked. Thanks a lot
Thanks, worked for me.
Thank you so much!!!! You saved me big time!
Worked like a charm! Thanks a ton!
Thanks a LOT mate. you make me happy. god bless you ;)
Thanks this worked and saved my time
It would help if you warned users to **TYPE** in “master” – NOT use the drop down as that gives an error when you attempt to .
How can I resolve it for SQL server 2008
R2. .
Simple solution. Thanks Pinal.
Short and crisp solution. It worked for me. Thanks I’ve used it on SQL Server 2012 express