Solved

SQL 2008 default database detached. Can't login.

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

919 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

23 Experts available now in Live!

Get 1:1 Help Now