Check if stored procedure is running

Stefan Rogin

How to check if a stored procedure or query is still running in SQL Server?

Ideas

  1. I've thought of having a log where to write when the procedure starts and delete when it ends.

    Flaws:

    • it leaves open the case when the server restarts or some kind of failure inside the procedure.
    • this method needs some work to be done before running the procedure, so it can't be applied on already running procedures.
  2. Use process monitor

I would prefer a solution that can be incorporated as a stored procedure with procedure_name and/or pid, parameters as input, so tracing programs or solutions using the SQL Server interface won't work.


Update #1


Usage example:

CREATE PROCEDURE dbo.sp_sleeping_beauty 
    @time_str varchar(50)
AS 
   SET NOCOUNT ON;
   WAITFOR DELAY @time_str;
GO

dbo.sp_sleeping_beauty '00:00:10'
dbo.sp_sleeping_beauty '00:00:20'
dbo.sp_sleeping_beauty '00:00:30'

the procedure should be called like

test_if_running 'dbo.sp_sleeping_beauty '00:00:20''

and return true while running (for 20 seconds) and false after or if the function fails or the system is restarted

bummi

You might query sys.dm_exec_requests which will provide sesion_ID, waittime and futher rows of interest and CROSS APPLY sys.dm_exec_sql_text filtering your query with the SQL for your procedure.

Select * from
(
SELECT * FROM sys.dm_exec_requests 
where sql_handle is not null
) a 
CROSS APPLY  sys.dm_exec_sql_text(a.sql_handle) t 
where t.text like 'CREATE PROCEDURE dbo.sp_sleeping_beauty%'

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Errors running stored procedure in workbench

From Dev

Stored Procedure Check if Parameter is NULL

From Dev

Running SQL query from a column in stored procedure

From Dev

Stored procedure not running correctly with dynamic sql text

From Dev

Find out if the stored procedure is already running

From Dev

How come modifying and running a stored procedure "fixes" it?

From Dev

Running a stored procedure with NodeJS and MSSQL package error

From Dev

error when running the stored procedure in mysql

From Dev

C# running temporary stored procedure

From Dev

error while running a stored procedure in mysql

From Dev

get spid of currently running stored procedure

From Dev

Keep Stored Procedure running even if there is error

From Dev

Issue running stored procedure from .net

From Dev

Partition Key Error when running Stored Procedure

From Dev

Stored procedure stops running but recompile fixes it

From Dev

Check if SELECT Returns Any Rows in Stored Procedure

From Dev

SQL Server Check If Stored Procedure Contains WITH(NOLOCK)

From Dev

How to efficiently check stored procedure for existence in PHP

From Dev

How to write stored procedure to check Grant in MySql?

From Dev

Update Oracle Stored Procedure to Introduce a Check

From Dev

Async execution of a long-running stored procedure via a webservice

From Dev

Oracle: Prevent a stored procedure from running outside of production environment

From Dev

Running a t-sql job step (stored procedure) with a proxy

From Dev

Running SQL Stored Procedure process without stopping on errors

From Dev

Running a Stored Procedure on All Databases, and Saving All Results Into A Table

From Dev

Oracle: Prevent a stored procedure from running outside of production environment

From Dev

Oracle stored procedure failing when running on linux, works on windows

From Dev

FreeTDS: How to set charset of parameters running stored procedure

From Dev

Error converting varchar to datetime when running stored procedure from code

Related Related

  1. 1

    Errors running stored procedure in workbench

  2. 2

    Stored Procedure Check if Parameter is NULL

  3. 3

    Running SQL query from a column in stored procedure

  4. 4

    Stored procedure not running correctly with dynamic sql text

  5. 5

    Find out if the stored procedure is already running

  6. 6

    How come modifying and running a stored procedure "fixes" it?

  7. 7

    Running a stored procedure with NodeJS and MSSQL package error

  8. 8

    error when running the stored procedure in mysql

  9. 9

    C# running temporary stored procedure

  10. 10

    error while running a stored procedure in mysql

  11. 11

    get spid of currently running stored procedure

  12. 12

    Keep Stored Procedure running even if there is error

  13. 13

    Issue running stored procedure from .net

  14. 14

    Partition Key Error when running Stored Procedure

  15. 15

    Stored procedure stops running but recompile fixes it

  16. 16

    Check if SELECT Returns Any Rows in Stored Procedure

  17. 17

    SQL Server Check If Stored Procedure Contains WITH(NOLOCK)

  18. 18

    How to efficiently check stored procedure for existence in PHP

  19. 19

    How to write stored procedure to check Grant in MySql?

  20. 20

    Update Oracle Stored Procedure to Introduce a Check

  21. 21

    Async execution of a long-running stored procedure via a webservice

  22. 22

    Oracle: Prevent a stored procedure from running outside of production environment

  23. 23

    Running a t-sql job step (stored procedure) with a proxy

  24. 24

    Running SQL Stored Procedure process without stopping on errors

  25. 25

    Running a Stored Procedure on All Databases, and Saving All Results Into A Table

  26. 26

    Oracle: Prevent a stored procedure from running outside of production environment

  27. 27

    Oracle stored procedure failing when running on linux, works on windows

  28. 28

    FreeTDS: How to set charset of parameters running stored procedure

  29. 29

    Error converting varchar to datetime when running stored procedure from code

HotTag

Archive