Guest User

Untitled

a guest
Oct 22nd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. /*Deadlock Error Handling example*/
  2.  
  3. /*You can insert this code into a stored proc*/
  4.  
  5. BEGIN TRY
  6. /*Place SQL Code in here*/
  7. SELECT 'Test' /*Dummy code*/
  8. END TRY
  9. BEGIN CATCH
  10. IF (ERROR_NUMBER() = 1205)
  11. BEGIN
  12. SELECT 'Process has been deadlocked. Please check logs or Extended events for more detail'
  13. END
  14. ELSE /*If Error is not a deadlock, let's display what type of error it is*/
  15. BEGIN
  16. /*Declare variables to hold error information*/
  17. DECLARE @ErrorMessage NVARCHAR(max),
  18. @ErrorSeverity INT,
  19. @ErrorState INT;
  20. SELECT @ErrorMessage = ERROR_MESSAGE(),
  21. @ErrorSeverity = ERROR_SEVERITY(),
  22. @ErrorState = ERROR_STATE();
  23. /*Now let's raise the error*/
  24. RAISERROR( @ErrorMessage, @ErrorSeverity, @ErrorState);
  25. END
  26.  
  27. END CATCH
Add Comment
Please, Sign In to add comment