事实证明,我不想锁定表,我只想一次执行一个存储过程。在C#代码中,我将在另一个对象上放置一个锁,这就是这里所讨论的内容
http://www.sqlservercentral.com/Forums/Topic357663-8-1.aspx
那就是我用的
declare @Result intEXEC @Result =sp_getapplock @Resource = 'holdit1', @LockMode = 'Exclusive', @LockTimeout = 10000 --Time to wait for the lockIF @Result < 0BEGINROLLBACK TRANRAISERROR('Procedure Already Running for holdit1 - Concurrent execution is not supported.',16,9)RETURN(-1)END其中“ holdit1”只是锁的名称。
@result如果成功获得锁,则返回0或1(其中之一是立即成功获得锁,另一个是您在等待时获得锁)



