Solved

SQL 2008 default database detached. Can't login.

Posted on 2011-03-18
3
784 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
  • 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now