Solved

SQL Server 2008 - Can't Drop DB

Posted on 2012-04-11
9
801 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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.
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
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

705 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