Return to Snippet

Revision: 50908
at September 8, 2011 18:04 by sommertim


Initial Code
1) Get the processes attached to that database:

  SELECT spid  FROM master..sysprocesses  WHERE dbid = DB_ID(@DatabaseName)
  AND spid != @@SPID

Note :  @@SPID  is your connected instance Service Process id "SPID"

2) Perform Kill operation in a loop or use cursor

  EXEC('KILL '+RTRIM(@spid) )

Initial URL


Initial Description
Kill connections to a database to perform maintenance that requires a connectionless DB

Initial Title
List and kill active DB connections

Initial Tags
sql

Initial Language
SQL