因為是特定的主機,當然只能 Kill 特定的 spid
只好先抓出那台主機所有 spid 來進行刪除的動作
DECLARE @spid int, @SQLstr nvarchar(128) DECLARE spids_cr CURSOR FOR SELECT p.spid FROM sys.sysprocesses P JOIN sys.sysdatabases D ON (D.dbid = P.dbid) JOIN sys.sysusers U ON (P.uid = U.uid) WHERE hostname != '' AND hostname = @hostname AND [P].[program_name]='.Net SqlClient Data Provider ' FOR READ ONLY OPEN spids_cr FETCH spids_cr INTO @spid WHILE (@@FETCH_STATUS=0) BEGIN SET @SQLstr = 'KILL ' + CAST(@spid AS varchar) EXEC sp_executesql @SQLstr FETCH spids_cr INTO @spid END CLOSE spids_cr DEALLOCATE spids_cr參考:http://www.stev.org/post/2011/03/01/MS-SQL-Kill-connections-by-host.aspx http://sharedderrick.blogspot.tw/2008/01/kill-all-connection.html
沒有留言:
張貼留言