Kash Farooq's software development blog

.NET Developer

How to force SQL Server to drop DB connections

Posted by Kash Farooq on February 20, 2013

I keep on needing this script so I thought I’d post it here.

Use Master
Go

Declare @dbname sysname
Set @dbname = '<YOUR DATABASE NAME>'

Declare @spid int
Select @spid = min(spid) from master.dbo.sysprocesses
where dbid = db_id(@dbname)

While @spid Is Not Null
 Begin
 Execute ('Kill ' + @spid)
 Select @spid = min(spid) from master.dbo.sysprocesses
 where dbid = db_id(@dbname) and spid > @spid
 End
Advertisements

Sorry, the comment form is closed at this time.

 
%d bloggers like this: