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
WAW! IT WORKED..
I created a SQL server (2012 Standard) login account with a domain group, mydomain\abcgroup. The domain group, ‘abcgroup’, contains several domain users, and one of users is named mydomain\john. A database named ‘abcprod’ is created by a SQL super user. Under database ‘abcprod’->Security->users, I create a user name ‘abcgroup_team’, and it contains the server login account ‘mydomain\abcgroup’ above, and I gave whatever read/write permission to this username. My goal is create a login account as a domain group, and let the group leader to handle the users in the group, rather than creating each single user account in my SQL server. Can I do this? However, when john, a group member in mydomain\abcgroup, tried to log on, he got the SQL error number “4046”. Do I miss anything and how to find the problem?
Sorry, I meant “4064” error. My typo for “4046”.
Originally, the default database for mydomain\abcgroup was ‘mytrial’, and I had ‘abcgroup_team’ created under database ‘mytrial’->Security->users. The user ‘john’ was able to log on. Then I removed ‘mytrial’->Security->users->abcgroup_team, and create the same username under ‘abcprod’->Security->users. Then ‘john’ was not able to log on anymore. However, if I re-create ‘mytrial’->Security->users->abcgroup_team, ‘john’ was able to log on again. When ‘mytrial’->Security->users-abcgroup_team is removed, I used SQL superuser to run ALTER login [abcgroup_team] with DEFAULT_DATABASE = abcprod. It still did not help. Why was ‘john’ not able to log in if its original username ‘mytrial’->Security->users->abcgroup_team is deleted? How can I convert the login from ‘mytrial’ to ‘abcprod’?
Thanks for this.
Thanks Gr8…
Thanks a lot …its saved my time…
Thank you sir.
Pinal You are guineus…
You proved god for me today….
Thank you pinal fabulous
Thaaaaaaaanks a lot!
Yes! Thanks!
Thanks ! appreciate a ton.
Thanks a lot Pinal, it fixed the issue for me.
Thanks so much. good solution!
NEED HELP …….
I am using visual basic 2008 express edition with sql server 2008…. I hv created a database in vb2008 express ed. and also added a dataset to be used in the form. But whatever I am trying to add, insert or delete into the table “Users” of my database, changes are reflected in dataset only. Once application closed, all changes are vanished…not reflected in database…why ..do i need to make some settings so that the changes are reflected in the database also once the aplication is closed….Please can somebody guide me on this……
I have the problem above but my DAC is disabled. How can I solve this problem?
Consider one scenario you can’t able to enter in to server because your Master Database get corrupted. In this condition what will you do?
[email removed]
My solution was a little different. I tried the ALTER LOGIN [mydomain\myuser], but it did not work (The user was logging in using Windows Authentication). Instead, I used ALTER LOGIN [NT AUTHORITY\SYSTEM] and it worked
Pinal Dave, that did the trick. You Rock! Love your website!
Thanks for the tip, you solved my problem!
Thank you soo much!!!