This little script’s helped me numerous times when refreshing environments manually from backups and had to ensure there were no left-over connections left which would’ve made the restores fail. Without furtherĀ a due:
1234567891011121314151617181920212223242526DECLARE @dbspid AS int
DECLARE @killcommand AS varchar(50)
DECLARE ConnectionKiller CURSOR FOR
SELECT sysproc.spid FROM sysprocesses AS sysproc
INNER JOIN sysdatabases AS sysdb ON
sysdb.dbid = sysproc.dbid
WHERE sysdb.NAME IN [...]
