SQL Server 2008 - Can't Drop DB

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?
cbridgmanAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Anthony PerkinsConnect With a Mentor Commented:
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
 
David L. HansenProgrammer AnalystCommented:
USE MASTER
GO
ALTER DATABASE YourDBName
SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
DROP DATABASE YourDBName
GO
0
 
cbridgmanAuthor Commented:
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
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
cbridgmanAuthor Commented:
The query that you provided has been running now for 15 minutes. Should I just let it keep going?
0
 
David L. HansenProgrammer AnalystCommented:
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
 
cbridgmanAuthor Commented:
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
 
Anthony PerkinsCommented:
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
 
cbridgmanAuthor Commented:
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
 
cbridgmanAuthor Commented:
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
All Courses

From novice to tech pro — start learning today.