aşağuıdaki script ile tüm etkin olmayan bağlantıları toplu bir şekilde kapatabilirsiniz.
1: DECLARE @user_spid INT
2: DECLARE CurSPID CURSOR FAST_FORWARD
3: FOR
4: SELECT SPID
5: FROM master.dbo.sysprocesses (NOLOCK)
6: WHERE spid>50 -- avoid system threads
7: AND status='sleeping' -- only sleeping threads
8: AND DATEDIFF(HOUR,last_batch,GETDATE())>=24 -- thread sleeping for 24 hours
9: AND spid<>@@spid -- ignore current spid
10: OPEN CurSPID
11: FETCH NEXT FROM CurSPID INTO @user_spid
12: WHILE (@@FETCH_STATUS=0)
13: BEGIN
14: PRINT 'Killing '+CONVERT(VARCHAR,@user_spid)
15: EXEC('KILL '+@user_spid)
16: FETCH NEXT FROM CurSPID INTO @user_spid
17: END
18: CLOSE CurSPID
19: DEALLOCATE CurSPID
20: GO