20/02/2008, 18:46
|
| Colaborador | | Fecha de Ingreso: julio-2007 Ubicación: Mexico, D.F.
Mensajes: 6.482
Antigüedad: 17 años, 5 meses Puntos: 180 | |
Re: Conexiones abiertas Algo aun mas fino:
-- Desconecta a los usuarios de "x" base
-- IIslas 2008
CREATE PROCEDURE pr_DesconectaUsuarios
@Database sysname
AS
BEGIN
Set nocount on
Declare @nOrden int
Declare @nOrdenMax int
Declare @cSQL nvarchar(1000)
if object_id('tempdb..#spid') is not null
Drop table #spid
set @cSQL = ''
Select identity(int,1,1) as nOrden ,
d.dbid as dbId,
d.name as dbName,
loginame as LoginName,
spid as SpId,
'Kill ' + str(spid) as cSQL
Into #spid
From master..sysprocesses p,
master..sysdatabases d
Where p.status != 'BACKGROUND'
And d.dbid = p.dbid
And d.name = @Database
if (select count(*) from #spid) = 0
return(0)
Select dbId,dbName,spid,LoginName,cSQL
From #spid
Select @nOrden = min(nOrden ),
@nOrdenMax = max(nOrden)
From #spid
While @nOrden <= @nOrdenMax
Begin
Select @cSQL = cSQL
From #spid
Where nOrden = @nOrden
Exec sp_executesql @cSQL
Set @nOrden = @nOrden + 1
End
END |