본문 바로가기

Server Story..../MSSQL

특정 사용자 세션 삭제 차단

/*

declare @counts int,@killid int,@username varchar(50)

set @counts=(select COUNT(*) from sysprocesses where loginame=@username)

while @counts>0

begin

set @killid=(select top 1 convert(int,spid) from sysprocesses where loginame=@username)

exec ('kill ' + @killid)

set @counts=@counts -1 

End

*/



프로시져로 만들면..



USE [master]

GO


/****** Object:  StoredProcedure [dbo].[killuser]    Script Date: 10/18/2013 14:28:27 ******/

SET ANSI_NULLS ON

GO


SET QUOTED_IDENTIFIER ON

GO



CREATE PROCEDURE [dbo].[killuser] 

@username varchar(50)

AS

BEGIN

SET NOCOUNT ON;

declare @counts int,@killid int

set @counts=(select COUNT(*) from master..sysprocesses where loginame=@username)

while @counts>0

begin

set @killid=(select top 1 convert(int,spid) from master..sysprocesses where loginame=@username)

exec ('kill ' + @killid)

set @counts=@counts -1 

End



END



GO