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.
| Author |
Topic |
|
AsimKhaliq
Yak Posting Veteran
94 Posts |
Posted - 2004-07-12 : 12:21:09
|
| HiI 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)asdeclare @sqlStatement varchar(255)declare @spid intdeclare curUsers cursor for select spid from sysprocesses where dbid = db_id(@dbName)while (select count(*) from sysprocesses where dbid = db_id(@dbName)) > 0begin 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 curUsersenddeallocate curUsersGO 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.MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
|
|
|