• Here is a variation of the kill script that can be used on any database whether or not it is the current database. To use, set the @dbname variable to the name of the database where the connections are to be killed.

    declare @dbname sysname, @spid int, @cnt int, @sql varchar(2048)

    set @dbname = 'targetDB'

    select @spid = min(spid), @cnt = count(*)

    from master.dbo.sysprocesses

    where dbid = db_id(@dbname) and spid != @@spid

    print @dbname + ' connection process(es) to kill: ' + rtrim(@cnt)

    while @spid is not null

    begin

    print 'kill connection process ' + rtrim(@spid)

    set @sql = 'kill ' + rtrim(@spid)

    exec(@sql)

    select @spid = min(spid), @cnt = count(*)

    from master.dbo.sysprocesses

    where dbid = db_id(@dbname)

    and spid != @@spid

    end

    print 'done'