Posts

Showing posts with the label kill session

SQL Server: Killing Sessions through T-SQL

DECLARE @DatabaseName nvarchar(50) SET @DatabaseName = N'Works' --SET @DatabaseName = DB_NAME() DECLARE @SQL varchar(max) SET @SQL = '' SELECT @SQL = @SQL + 'Kill ' + Convert(varchar, SPId) + ';' FROM MASTER..SysProcesses WHERE DBId = DB_ID(@DatabaseName) AND SPId <> @@SPId -- SELECT @SQL EXEC(@SQL) Source: http://www.kodyaz.com/articles/kill-all-processes-of-a-database.aspx

Invoking privilege to a user without giving ALTER SYSTEM directly

create or replace procedure kill_session( p_sid in varchar2, p_serial# in varchar2) is cursor_name pls_integer default dbms_sql.open_cursor; ignore pls_integer; BEGIN select count(*) into ignore from V$session where username = USER and sid = p_sid and serial# = p_serial# ; if ( ignore = 1 ) then dbms_sql.parse(cursor_name, 'alter system kill session ''' ||p_sid||','||p_serial#||'''', dbms_sql.native); ignore := dbms_sql.execute(cursor_name); else raise_application_error( -20001, 'You do not own this session ''' || p_sid || ',' || p_serial# || '''' ); end if; END; / Now I have created synonym under that user who wants this privilege create or replace synonym USERNAME.KILL_OWN_SESSION for SYS.KILL_SESSION; Now I connect ...