Solved

SQL Server 2008 - Can't Drop DB

Posted on 2012-04-11
9
854 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
[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
  • 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

752 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