Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Server 2008 - Can't Drop DB

Posted on 2012-04-11
9
Medium Priority
?
963 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 

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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

876 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