Cannot Open User Default Database (error 4064)

Wow weeee...  did I ever just make a blunder!  I wanted to do some performance tuning on a SQL Express DB.  So I detached the DB from SQL Express and Attached it to SQL Server.  I did my tuning (created a bunch of recomended indexes) and was about to reverse the process.  When I went to re-attach the DB to SQL Express boom...  “Cannot Open User Default Database (error 4606).  DOH!  My bad.  I didn't know the sa password and both my one sql server authentication account and my windows integrated authentication account threw the error message from SQL Express.  Luckily I found help on the MSDN Forum.  But I had to search just the right way to find it.

So without repeating everything in the forum here are the quick steps I followed using SQL Server Management Studio to get in.

1. Start SQL Express server if it isn't already.

2. On the Login click the “Options” button.

3. In the “Connect To Database” drop down box type in “master” without the quotes. 
(This is the misleading part of the UI.  I didn't realize I could just type in a db to connect to I thouht I had to select from the list.  Bad UI design!)

4. Now you should be able to login succesfully.

5. Run this script;
ALTER LOGIN [BUILTIN\Administrators] WITH DEFAULT_DATABASE=master
GO

Assuming your account belongs to the Administrators group, you should be home free...  You can reattach the needed DB or do whatever else you have to do.

--chaz

Print | posted on Friday, August 25, 2006 9:55 AM

Feedback

# re: Cannot Open User Default Database (error 4064)

Left by Can at 9/3/2006 5:13 AM
Gravatar Thank you,although the query doesn't work with me but anyways I can connect now:)

# re: Cannot Open User Default Database (error 4064)

Left by Wayne Jagger at 11/16/2006 2:34 PM
Gravatar Thank you so much. Worked first time !!!

# re: Cannot Open User Default Database (error 4064)

Left by Revathi at 12/15/2006 1:23 PM
Gravatar Hi,
Thanks a lot.

# re: Cannot Open User Default Database (error 4064)

Left by Kashish at 3/28/2007 8:30 PM
Gravatar Thanks a lot!!!It did work for me.

# re: Cannot Open User Default Database (error 4064)

Left by Fachmann at 7/18/2007 8:24 PM
Gravatar Great!!!!! Thanks a loooot!!!

# re: Cannot Open User Default Database (error 4064)

Left by BillV at 7/19/2007 8:27 AM
Gravatar Hey Fachmann,

Did you substitute the string [BUILTIN\Administrators]with something else or enter as is?

Please advise as I am having similar problem.

Thanks

# re: Cannot Open User Default Database (error 4064)

Left by cj at 8/7/2007 2:26 AM
Gravatar Folks,

If you are using a domain account and it doesn't happen to be in the administrators group substitute the above for this:

[Domain\youraccount] That is what I had to do.

# re: Cannot Open User Default Database (error 4064)

Left by james at 9/11/2007 8:51 AM
Gravatar you r a *, thnks

# re: Cannot Open User Default Database (error 4064)

Left by Florian at 9/14/2007 7:09 AM
Gravatar THANK you ... it's really work :).

# re: Cannot Open User Default Database (error 4064)

Left by William at 9/18/2007 1:50 PM
Gravatar Thanks so much. I had a panic attack when I dropped an old database and couldn't get back in. The query worked perfectly, of course because I had the specified login setup. For those using a different login, obviously you need to specify your own login in place of [BULITIN\Administrators]. Thanks again for this blog post.

# re: Cannot Open User Default Database (error 4064)

Left by Adam Gurno at 10/11/2007 11:19 AM
Gravatar Thanks for this. It saved my butt as I didn't realize you could simply type the database into the 'default database' combo box.

Keep up the good work!

# re: Cannot Open User Default Database (error 4064)

Left by Rathnavathi at 2/20/2008 11:50 PM
Gravatar Thanks a lot! It worked successfully.

# re: Cannot Open User Default Database (error 4064)

Left by Ewan at 3/3/2008 12:13 PM
Gravatar Didn't fully work for me, because the sa user still did not get updated for the default master DB. So once I had dropped the login with the script, I conected back into the database using the Windows Authentication login and used the Admin login for the server, and was then abble to set a default database for sa. Ok after that.

# good

Left by PHU at 3/17/2008 12:19 AM
Gravatar EXCELLENCE

# re: Cannot Open User Default Database (error 4064)

Left by Camille Trapp at 3/26/2008 10:30 AM
Gravatar Thank you, whoever you are, for taking the time to post the solution. I thought I would have to leave town.

# re: Cannot Open User Default Database (error 4064)

Left by Fernando at 4/8/2008 2:44 AM
Gravatar found your article on goolge. you saved my life!

# re: Cannot Open User Default Database (error 4064)

Left by Jigar at 4/22/2008 8:53 AM
Gravatar Thanks a lot. You haved my time. Great work. Thanks agian...

# re: Cannot Open User Default Database (error 4064)

Left by Jeroen at 5/20/2008 3:04 AM
Gravatar Thanx! Works!

# re: Cannot Open User Default Database (error 4064)

Left by Fher at 5/30/2008 6:41 PM
Gravatar If all of the above doesnt work try this:

ALTER LOGIN [YOURMACHINENAME\Yourname] WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english]

# re: Cannot Open User Default Database (error 4064)

Left by Natalie at 6/5/2008 11:37 AM
Gravatar Thanks a lot! You saved my life! :o)

# re: Cannot Open User Default Database (error 4064)

Left by mm at 7/21/2008 11:34 AM
Gravatar thanks and many thanks!!!

# re: Cannot Open User Default Database (error 4064)

Left by hm at 8/7/2008 7:52 AM
Gravatar Superb! I was just about to do a reinstall and then I found this page! Thanks!

# re: Cannot Open User Default Database (error 4064)

Left by Laza999 at 8/19/2008 11:47 PM
Gravatar I saw my life flash before my eyes till I read this, THANK YOU SO SO SO MUCH!!

Your comment:





 
Please add 4 and 1 and type the answer here:

Copyright © Chip Lemmon

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski