BEGIN TRANSACTION;
EXEC @result = sp_getapplock @Resource = 'stp',
@LockTimeout = 0,
@LockMode = 'Exclusive';
IF @result NOT IN ( 0, 1 ) -- Only successful return codes
BEGIN
PRINT @result
RAISERROR ( 'Lock failed to acquire.', 16, 1 )
END
ELSE
BEGIN
/* previous code here */
EXEC @result = sp_releaseapplock @Resource = 'stp';
COMMIT TRANSACTION;
END
|