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
It worked for me.
Thanks Pinal Dave
Thanks for the tip.very good
Thanks for the help! 8 Years later and still a valid resource!
worked for mee too. thanks
Failed To connect to server
shiv-PC\SqlExpress (Microsoft.sqlserver.connectioninfo)
unable to do any operation on this server
Thank you so much- what a relief to be connected again!
I applied this solution though it didn’t solve my issue. I performed the fail over and tried again to verify and faced same issue again.
I have same issue with Vikrant Bam, It’s doesn’t work and had issue again.
You may want to capture a profiler.
Thanks Darrell. Your advice just solve my issue.
thanks. this solution is effective.
Thanks, problem solved.
Thank, work for me
Thanks @Linh for letting me know.
thanks, it’s worked for me
Thanks @rajasekhar
super……..
Thanks @Naga
If the above statement does not work due to permissions or other errors, try executing this stored procedure instead:
EXEC SP_DEFAULTDB [], ‘MASTER’
Thanks @Alex – I have not tested it. Are you sure this works?
Thanx, it works perfect!!!
Thanks Micha,
You are the best , I had big problem and you saved me
Thanks Mohammed
Thank you so much!!!! You saved me big time!
Thanks Gautam
Saved my day, you are the man! Thanks Pinal
I am glad that my blog assisted you. Thanks for letting me know. This keeps my passion alive.
Thanks from PL :)
Hi,
When we want to access sql db through new user after giving particular database permission, We unable to access database.