Solved

SQL Server 2008 - Can't Drop DB

Posted on 2012-04-11
9
808 Views
Last Modified: 2012-07-07
I have a database in SQL Server 2008 that I am trying, unsuccessfully, to delete. I open management studio, right click on the database, choose delete from the menu, and one of two things happens. One, SQL Server tells me that the database can't be deleted because it is in use or two, it "acts" as if it is going to work -- the "executing" wheel just spins and spins  but nothing happens.

I've tried to use the following without success:

USE Master;
GO
DROP DATABASE dbname;
GO

I get the same results with that as with using the Delete pick from the menu.

I've also tried the following but it just tells me that the query is executing and it never stops

ALTER DATABASE MyDatabaseName
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE

When I stop that query from executing, there are a bunch of lines in the output window which tell me "Nonqualified transactions are being rolled back. Estimated rollback completion: 100%".

I have stopped SQL Server and restarted it and I've stopped everything else that I can think could possibly connect to it. Any ideas?
0
Comment
Question by:cbridgman
  • 5
  • 2
  • 2
9 Comments
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 37835198
USE MASTER
GO
ALTER DATABASE YourDBName
SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
DROP DATABASE YourDBName
GO
0
 

Author Comment

by:cbridgman
ID: 37835205
Thanks but I already tried that. As I mentioned above, when I get to the Alter Database part, the query just runs and runs and runs. If I cancel the query, the results area has line after line after line of the following:

Nonqualified transactions are being rolled back. Estimated rollback completion: 100%


Should I just let the query run? I'm not sure how long to let it run before I give up. Does DB size have anything to do with it? My DB is a little over 6GB.
0
 

Author Comment

by:cbridgman
ID: 37835227
The query that you provided has been running now for 15 minutes. Should I just let it keep going?
0
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 37835247
I think this may help.  If you run this all the processes should be killed, allowing you to then drop the database.


USE master;
GO
ALTER DATABASE YourDBName
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
ALTER DATABASE YourDBName
SET MULTI_USER;
GO
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 

Author Comment

by:cbridgman
ID: 37835383
The problem is that the Alter Database ... Set Single User, once started, never stops running. It has run now for over an hour and 30 minutes (I just stopped it).

My guess is that it isn't working as intended. I'm certainly no expert though. Maybe I should just let it continue?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 37835607
You need to let all the transactions complete.  You can monitor to some extent what is going on by using sp_who.  As soon as it completes and there are no connections to the database as eevidenced by sp_who, you should be able to drop the database.
0
 

Author Comment

by:cbridgman
ID: 37835665
The following query has been running now for 2.5 hours.

USE master;
GO
ALTER DATABASE YourDBName
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;


Is that normal? Should I just let it continue?

Also, do I run sp_who against the master db or against the db that I want to delete?
0
 

Author Comment

by:cbridgman
ID: 37835817
Problem Resolved!

I was connecting to the server using Windows authentication. When I connected using SQL Server authentication (SA user), I was able to drop the database by simply right clicking it and choosing delete from the menu.

Since I solved the problem, what do I do about awarding points on this one?
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 37835858
Since I solved the problem, what do I do about awarding points on this one?
I find that odd to say the least and I suspect was just a coincidence.  If you have permission to drop a database you can do it, otherwise you are out of luck.  I suspect what was happening was that you were trying to drop the database while you were still in the same database.  By changing to sa all you did was connect to a different database be default (probably master).   In future, if you want to drop a database do it this way:
USE master
ALTER DATABASE [YourDatabaseName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DROP DATABASE [YourDatabaseName]

Since I solved the problem, what do I do about awarding points on this one?
Select your comment as the solution
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
In this article I will describe the Backup & Restore 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.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

895 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

15 Experts available now in Live!

Get 1:1 Help Now