SQL Server Hosting – HostForLIFE.eu :: Aborting/ Killing A Long Running Stored Procedure

Take a scenario, where you wrote a SQL stored procedure in MS SQL Server DBMS and made some mistake of not handling a scenario, where SP keeps running for an infinite time or takes hours to finish the required task.

In this case, basically you are stuck with SQL Server, which is consuming a huge amount of memory and blocking the Server for further use.

There can be 2 ways to handle this.

  1. Shutdown/Restart MS SQL Server
  2. Abort/ kill/ stop SP

Option 1 is not a practical way to handle it in some environments where other people are using SQL Server.

The way given below tells about using a second option.

This has 2 steps.

Step 1

Identify the Thread/ process which, is executing SP

Step 2

Kill the process

USP_LongRunningSP is the procedure name or the part of the procedure name, if you do not remember the entire name.