Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 DB drop with connected users

Author  Topic 

Blastrix
Posting Yak Master

208 Posts

Posted - 2005-09-30 : 13:22:13
Is there a way to force a DB drop even if user's are still connected to it? I have a script that runs automatically for unit testing my code that creates a new DB each time the suite starts. Before it tries to create it drops an existing DB, if it's there. Unfortunately if a previous testing pass didn't complete successfully, and there's lingering connections, there's no way to drop the DB, and a fresh instance cannot be created.

Is there a flag, or process I can use to force the drop, or to delete any connected instances?

ryanston
Microsoft SQL Server Product Team

89 Posts

Posted - 2005-09-30 : 15:26:35
Try setting the database to single user mode using the ROLLBACK IMMEDIATE option:

ALTER DATABASE myDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE

You should be able to drop the database after that. You'll abort the transactions of anyone that is doing work in the database though, so be aware...

Thanks,

----------------------
Ryan Stonecipher
Developer, Microsoft SQL Server Storage Engine, DBCC
(Legalese: This posting is provided "AS IS" with no warranties, and confers no rights.)
Go to Top of Page
   

- Advertisement -