Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
facemann
Starting Member
1 Post |
Posted - 2008-06-09 : 17:25:36
|
I have a simple stored procedure that is deadlocking when two users attempt to run it at the same time. If the procedure deadlocks, I don't want to fail, I just want to try again. I have installed a try-catch loop but it seems to get stuck in the loop and fail anyway. Any ideas?Here is the error:GetNextKey IN CATCH LOOP on MappingInstruction tableMsg 3609, Level 16, State 1, Procedure TrUDLD, Line 327The transaction ended in the trigger. The batch has been aborted.And here is the procedure:ALTER PROCEDURE [dbo].[GetNextKey]@TableName VARCHAR(25),@NextKey INT OUTPUT,@flag INT = 0ASDECLARE @RowCount INT, @Success CHAR(1)SET @Success = 'N'WHILE @Success = 'N'BEGINBEGIN TRANSACTIONBEGIN TRYUPDATE updb..KeyStorageSET lastkey = lastkey + 1WHERE tablename = @TableNameSELECT @ROWCOUNT = @@ROWCOUNTIF @ROWCOUNT = 1BEGINSELECT @NextKey = lastkeyFROM updb..keystorageWHERE tablename = @TableNameSET @Success = 'Y'ENDCOMMIT TRANSACTIONEND TRYBEGIN CATCHROLLBACK TRANSACTIONPRINT 'GetNextKey IN CATCH LOOP on ' + @TableName + ' table'WAITFOR DELAY '000:00:05' --wait five secondsSET @Success = 'N'END CATCHEND --WHILE @Success = 'N'GOIt seems to me that the loop should just keep on trying until it succeeds in updating the KeyStorage table. I don't understand why it fails. Any suggestions would be appreciated. |
|
|
|
|
|