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

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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.

# 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!!

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

Left by Prashant Raut at 9/11/2008 8:46 AM
Gravatar Thanks a ton for this. This was the quick turnaround. Saved lot of time

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

Left by sabrina at 9/20/2008 7:26 AM
Gravatar Vraiment je vous remercie pour la solution!!

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

Left by LGuimaraes at 9/23/2008 9:08 PM
Gravatar You save me a lot of time!!! Great job!!!

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

Left by John Paul at 9/24/2008 11:29 AM
Gravatar wow...the best..it works...thnk u so much..Godbless!Continue your good deeds!hehehe...

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

Left by John Paul at 9/24/2008 11:41 AM
Gravatar waahh..i am now connected to the sql server 2005 but why is it that i can't attach a database?is there any good someone that can help me???thanx in advance...

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

Left by Chris at 9/30/2008 10:48 AM
Gravatar Thanks, you saved my bacon!!!

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

Left by VWT at 10/23/2008 7:42 PM
Gravatar Thanks

Worked like a charm!

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

Left by simz at 10/28/2008 4:42 AM
Gravatar Thank you very much for posting this! It saved me a lot of hours and headaches.

Thanks!

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

Left by Ghulam Haider at 11/14/2008 2:17 AM
Gravatar Ooooohhhhh Thanks you solved my 2 hours problem just in half of minute. Thanks again thanks.

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

Left by TYev at 11/18/2008 5:25 AM
Gravatar Thanks! It is works!

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

Left by doris at 12/16/2008 5:13 PM
Gravatar thanks a lot. worked better than what microsoft put on their site.

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

Left by JoE at 3/4/2009 6:59 PM
Gravatar Eres lo maximo
thanks a lot.

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

Left by Per E at 4/9/2009 3:45 AM
Gravatar Thanks a lot, this helped me big time!

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

Left by Kevin at 5/8/2009 10:20 PM
Gravatar Thanks, this worked for me but first I had to run the sql server instance in single user mode by adding -m to the startup options.

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

Left by Na3than at 6/18/2009 2:40 PM
Gravatar Thanks for the reminder about the Options button on the login dialog. Another way to go, for those who eschew GUI tools, is to use SQLCMD with the -d option to connect to a specific database. From a command prompt: sqlcmd -S <server> -d master ... then at the SQLCMD prompt, type your ALTER LOGIN command, with GO on a separate line. If your Windows account isn't in the BUILTIN\Administrators group, use the -U option to specify another login.

# Super!

Left by Christina Pronegg at 8/6/2009 12:29 PM
Gravatar Schade, dass ich den Blogg erst heute gefunden habe - weiter so.

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

Left by Ramesh at 9/1/2009 5:16 AM
Gravatar Thanks a lot ...it's working...
Use below steps:

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 thought 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


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

Left by arun at 12/8/2009 6:17 AM
Gravatar Very-very thanks, it worked for me.

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

Left by Kumar at 3/3/2010 6:56 PM
Gravatar Thank you so much; I worked days around this problems, but to no avail.

It is just amazing; and it is simple. There are so many 'experts' on line who just make you walk in circles. You are a real saviour.

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

Left by Murli Krishna at 8/20/2010 4:40 AM
Gravatar Thanks a lot dude.. but does anyone know why this problem comes.. ?

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

Left by Surj at 5/31/2011 6:03 PM
Gravatar Awesome. This worked!

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

Left by Helenees at 11/22/2011 10:37 AM
Gravatar Very helpful. My default database was deleted while fixing profile issue. It saved me time to reinstall SQL server and Analysis Services (I thought I had to if I could not login to the server anymore).

Your comment:





 
 

Copyright © Chip Lemmon

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski