Search code examples
sql-serverstored-proceduressql-server-2000

Prevent a Stored Procedure from being executed twice at the same time


I have a stored procedure for SQL Server 2000 that can only have a single instance being executed at any given moment. Is there any way to check and ensure that the procedure is not currently in execution?

Ideally, I'd like the code to be self contained and efficient (fast). I also don't want to do something like creating a global temp table checking for it's existence because if the procedure fails for some reason, it will always be considered as running...

I've searched, I don't think this has been asked yet. If it has been, sorry.


Solution

  • yes there is a way. use what is known as SQL Server Application locks.

    EDIT: yes this also works in SQL Server 2000.