Drop a sql server database by killing all associated processes

 

To drop a sql server database using a script, it is required that there be no open sql processes referencing the database else you get the error

Drop failed for Database  northwind.  (Microsoft.SqlServer.Smo)

Cannot drop database “northwind” because it is currently in use. (Microsoft SQL Server, Error: 3702)

In order to avoid this error you can use the following script that detects and kills all processes associated with the database

 

Advertisements

About 925coder

Father. Husband. Programmer. In that order. I love writing code, in all languages, all platforms. In my day job I am the lead architect in a software company creating products for the finance industry, mostly using Microsoft .NET technologies.

Posted on May 10, 2011, in Tech. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: