Zum Inhalt springen

Cancel a user session / process in SQLServer Flex

Zuletzt aktualisiert am

Cancels a user process in SQLServer Flex that is based on the session ID.

Cancel the session / process with the stored procedure kill_sessions

Section titled “Cancel the session / process with the stored procedure kill_sessions”

With the following Stored Procedure you will be able to cancel a user process / session for:

  • a database (currently only user databases are considered) - When specified, cancel all SPIDs inside of the database.

exec [msdb].[STACKIT].[kill_sessions] @database_name = ‘dbnameScreenshot of an SQL query tool showing a custom stored procedure to cancel user sessions. The top editor pane shows the code "exec msdb.STACKIT.kill_sessions" with the parameter "@dbname = 'DB02'". Below it, the "Results" tab displays a grid log of four distinct sessions within database 'db02' being successfully cancelled, including details like ErrorNumber, ErrorSeverity, and specific cancellation messages for each session ID.

  • a user name - When specified, cancels all SPIDs under the login name.

exec [msdb].[STACKIT].[kill_sessions] @login_name = ‘loginnameScreenshot of an SQL query tool showing the stored procedure to cancel sessions by login name. The top editor pane displays the code "exec msdb.STACKIT.kill_sessions" with the parameter "@loginname = 'loc_user02'". Below it, the "Results" tab shows a grid log with two rows detailing the cancellation of sessions 55 and 60 belonging to user 'loc_user02' in database 'db02'.

  • a session ID - When specified, cancels the selected SPID.

exec [msdb].[STACKIT].[kill_sessions] @sID = number Screenshot of an SQL query tool showing the stored procedure to cancel a specific session ID. The top editor pane displays the code "exec msdb.STACKIT.kill_sessions" with the parameter "@sID = 55". Below it, the "Results" tab shows a single-row grid log confirming that session 55 for user 'loc_user02' in database 'db02' was successfully cancelled.

Only users with the following database roles can run the Stored Procedure.

  • ##STACKIT_ProcessManager##
  • ##STACKIT_ServerManager##