Greeting Everyone
I just want to confirm that my code for locking is sound. I thought it was, but after a couple of multi-user related problems I am now not so sure.
I leave most locking issues to SQL itself, but have a table containing next transaction numbers, where I recognise that locking hint is required. After taking the next transaction number I increment it. My current coding is as below:
-----------------------------------
BEGIN TRANSACTION
SET @intTID = (SELECT N_Number
FROM tblNextNumbers With (UPDLOCK)
WHERE N_Reference = 1)
UPDATE tblNextNumbers
SET N_Number = N_Number+1
WHERE N_Reference=1
... more updates using @intTID
COMMIT TRANSACTION
-----------------------------------
I thought this code was OK, but 2 users have been assigned the same number in recent times.
Where is my problem?
Thanks in advance.
Robert
I just want to confirm that my code for locking is sound. I thought it was, but after a couple of multi-user related problems I am now not so sure.
I leave most locking issues to SQL itself, but have a table containing next transaction numbers, where I recognise that locking hint is required. After taking the next transaction number I increment it. My current coding is as below:
-----------------------------------
BEGIN TRANSACTION
SET @intTID = (SELECT N_Number
FROM tblNextNumbers With (UPDLOCK)
WHERE N_Reference = 1)
UPDATE tblNextNumbers
SET N_Number = N_Number+1
WHERE N_Reference=1
... more updates using @intTID
COMMIT TRANSACTION
-----------------------------------
I thought this code was OK, but 2 users have been assigned the same number in recent times.
Where is my problem?
Thanks in advance.
Robert