Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 how to disconnect all the applications while resto

Author  Topic 

AsimKhaliq
Yak Posting Veteran

94 Posts

Posted - 2004-07-12 : 12:21:09
Hi
I am running a job to restore my database but i want to disconnect all to my application using the same database.

Thnx in adv

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-07-12 : 13:32:49
We use this. Place it in master and just call it with the database name as a parameter.


CREATE proc uspKillDBConnections -- uspKillDBConnections 'pubs'
(
@dbName sysname
)
as
declare @sqlStatement varchar(255)
declare @spid int
declare curUsers cursor for
select spid
from sysprocesses
where dbid = db_id(@dbName)
while (select count(*) from sysprocesses where dbid = db_id(@dbName)) > 0
begin
waitfor delay '00:00:03'
open curUsers

fetch next from curUsers into @spid

while (@@fetch_status <> -1)
begin
select @sqlStatement = 'kill ' + cast(@spid as varchar)
exec(@sqlStatement)

fetch next from curUsers into @spid
end

close curUsers
end
deallocate curUsers

GO


Yeah, yeah. Even I have some stuff with cursors in it still. Someday in the distant future I'll get around to converting it. The clone wars will probably be over by then though.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -