0
我發現這個例子中,以避免如果它仍在運行,運行SP:這是sp_getapplock鎖定返回值的值嗎?
CREATE PROCEDURE some_sp AS
DECLARE @ret int,
@lockresource sysname
SELECT @lockresource = object_name(@@procid)
BEGIN TRY
EXEC @ret = sp_getapplock @lockresource, @LockMode = 'Exclusive',
@LockOwner = 'Session', @LockTimeout = 5
IF @ret <> 0
BEGIN
RAISERROR ('Another instance of the procedure is already running, 16, 1)
RETURN
END
-- Do stuff
EXEC sp_releaseapplock @lockresource, 'Session'
END TRY
BEGIN CATCH
IF @@trancount > 0 ROLLBACK TRANSACTIOn
EXEC sp_releaseapplock @lockresource, 'Session'
END CATCH
但我不知道這是否是我所期待的。
如果SP正在運行,那麼@ret的值是多少?
EXEC @ret = sp_getapplock @lockresource, @LockMode = 'Exclusive',
@LockOwner = 'Session', @LockTimeout = 5
如果它沒有運行,它的價值是什麼?
我檢查這個page,但我不明白。