SELECT db_name(dbid) as DatabaseName, count(dbid) as NoOfConnections,
loginame as LoginName
FROM sys.sysprocesses
WHERE dbid > 0
GROUP BY dbid, loginame
Asi para elminar las conexiones suspendidas podemos aplicar este TSQL
USE MASTER
GO
DECLARE @dbname sysname
SET @dbname = 'Suscripciones'
DECLARE @spid SMALLINT
DECLARE @KILL nVARCHAR(100)
DECLARE kill_cursor3 CURSOR FOR
select spid
from master..sysprocesses
where status = 'sleeping' AND dbid = db_id(@dbname) and loginame like '%sa%' and cpu=0 and hostname like 'servidor%'
OPEN kill_cursor3
FETCH NEXT FROM kill_cursor3 INTO @spid
WHILE @@FETCH_STATUS = 0
BEGIN
SET @KILL= 'kill '+cast(@spid as nvarchar(10))
EXEC sp_executeSQL @KILL
FETCH NEXT FROM kill_cursor3 INTO @spid
END
Close kill_cursor3
Deallocate kill_cursor3
Fuente:
Comentarios
Publicar un comentario