Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL 2008 default database detached. Can't login.

Posted on 2011-03-18
3
Medium Priority
?
796 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 1500 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

688 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