Solved

SQL 2008 default database detached. Can't login.

Posted on 2011-03-18
3
792 Views
Last Modified: 2012-05-11
ISSUE: SQL Server 2008 database has been detached. All logins had this database as default database. Now, all users can log into the server and can run queries on the other databases on the same server, but none of the logins can perform any actions from Management Studio, i.e., backup, restore, view or edit database or login properties, etc.
The error displayed is:
"Cannot open user default database. Login Failed.
  Login failed for user 'sa'. Microsoft SQL Server, Error: 4064"

The server is SQL Server 2008 running on a Windows XP development box.
The databases are all SQL Server 2000 compatible.

REQUEST: Is there a way to regain access at some level so we can re-attach the database? Possibly change the login's default database via TSQL query?

0
Comment
Question by:cfgunnyNsite
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
beta911 earned 500 total points
ID: 35167112
You can resolve this by specifying another database you want to connect to; master, for example. Then you can reset the login's default database. With sqlcmd, you can do the following:

sqlcmd -d master -U sa -P mypassword

and then:

alter login sa with default_database = master
0
 

Author Comment

by:cfgunnyNsite
ID: 35168580
beta911:,
Thanks! I should have thought of that. Been under a LOT of pressure on this project and it shows. Boy, do I feel stupid.
Actually, I had to tweak your suggestion a bit. If I log into another database as 'sa', it will still try to create a new connection as 'sa' for each menu command I attempt. It still attempts with the default database and erorrs out. But you did get me going. While logged into 'master', I created another user, via script, with sysadmin privilages and 'master' as the default database. I disconnected and reconnected as the new user and I have full access. I then changed the default database for all the other users, re-attached the original database and I'm in business, again.

Thanks, again.
Points awarded for knowledge and patience.
0
 

Author Closing Comment

by:cfgunnyNsite
ID: 35168608
Solution may have worked on earlier version. Tweaked solution to work on GUI.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question