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
You save my life lol thank u so much!!!
Thanks man, saved me a lot of time
Thank you… This helped!
excelent solution, I needed this, thnks
Worked Perfectly!! Thanks!
Thank you very much
Thank you very much…
Solver thanks!
I had this connection problems when importing data-tier from a bacpac file to a new database
settint default database to master solved it!
Thanks!!!
Issue solved thanks
Awesome thanks man u a genius
You are the life saver.
We are moving DBs to new servers before cutover. I moved couple of them that are relate one application. I then detached them just to see if the application still works. Then I tried come back to do the others but could not login. Glad found your article.
Also, I have found quite a few answers from you other articles before.
Thanks!
perfect solution tanks
thanks bro…
Thank you for your tips and tricks, as always you are a life saver.
thanks master. google first link with perfect answer
11/10 for that one! Saved my Sunday. Tip dont take your OWN default database OFFLINE when you’re the only sysadmin in on a weekend. Lesson learned
and leave your default to tempdb or master….
Really very useful trick…Thanks a lot
Thank you. This really helped!