Lock/Unlock Stored Procedure during execution time.

Ranjeet_8
Posted by Ranjeet_8 under ASP.NET category on | Points: 40 | Views : 2183

CREATE PROCEDURE [dbo].[Your_SP_Name]
(
// Declare Your Parameters.
)
AS
BEGIN
SET NOCOUNT OFF;

SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
BEGIN TRANSACTION

DECLARE @LockResult int;
EXECUTE @LockResult = sp_getapplock
@Resource = 'RepeatableRead_TRANSACTION',
@LockMode = 'Exclusive',
@LockTimeout = 0

// Write Your QUERY Here.

EXECUTE sp_releaseapplock
@Resource = 'RepeatableRead_TRANSACTION'
COMMIT TRANSACTION
END

Comments or Responses

Login to post response