Posts

Showing posts with the label Sp_getapplock

SQL Server, prevent users from executing the same stored procedure at the same time. SP_GETAPPLOCK and SP_RELEASEAPPLOCK

Image
Hi Guys, Today just a short post in which we will see how to prevent users from executing the same stored procedure at the same time . I think it's a very useful thing to know and in some cases it can save us the day. Furthermore, this could be useful for building a more robust procedure.   Enjoy the reading!   Sp_getapplock & Sp_releaseapplock First of all, you should know that SQL Server offers two procedure which have been developed for this purpose. These two stored procedure are sp_getapplock and sp_releaseapplock. The logic behind these functions is as follows:  We have a resource that we want to be executed by only one process at a time. With stored procedure Sp_GetApplock we ​​can set a lock on a resource so that a second process finds this resource already in use. The stored procedure sp_releaselock instead removes the lock from the resource. Before giving an example to understand how to use these functions let's see the parameters: The sp_getapplock puts ...