Script to Kill all the connections for the database in sqlserver2005

Posted: June 4, 2010 in Scripts to use

Below script will help you to kill all the existing connection coming to the user databases.
Copy and paste the script in Query window and change the DBName to the one that you want to troubleshoot.

DECLARE @DatabaseName nvarchar(50)
SET @DatabaseName = N”

DECLARE @SQL varchar(max)
SET @SQL = ”

SELECT @SQL = @SQL + ‘Kill ‘ + Convert(varchar, SPId) + ‘;’
FROM master..sysprocesses
WHERE DBId = DB_ID(@DatabaseName) AND SPId @@SPId



Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s