|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, May 08, 2013 7:23 AM
Points: 199,
Visits: 136
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 1:49 AM
Points: 1,131,
Visits: 855
|
|
Great article, but I think you forget one thing: What about xact_state() ?
I've seen somewhere (might have been BOL) that this code should work: if (XAXT_State()) = -1 RollBack Transaction
But I'm uncertain if I should add it to all my try-catch blocks. What do you think?
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, May 08, 2013 7:23 AM
Points: 199,
Visits: 136
|
|
XACT_STATE has 3 possible values. 0 = there is no transaction 1 = Transaction can be committed -1 = Transaction should be rolled back.
So, if your try-catch block needs to maintain TRANSACTIONs then your CATCH block should check for (XACT_STATE()) = -1 rolling back your transaction. You can start checking the condition (XACT_STATE()) <> 0 in your CATCH block.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 1:49 AM
Points: 1,131,
Visits: 855
|
|
Thank you very much for replying, but according to my BOL it has -1, 0 and 1 as values. Where do you get your 0,1,2 values from? TIA Henrik
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, April 12, 2013 5:54 AM
Points: 159,
Visits: 239
|
|
Just curious as to the overhead to use Try/Catch within TSQL / stored procedure. I'm assuming this is using the CLR and if you put this within a high volume, repeatedly used sproc, the performance hit involved?
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, May 08, 2013 7:23 AM
Points: 199,
Visits: 136
|
|
oops... sorry... a mistake... XACT_STATE states are 0,1 and -1 as you mentioned... I used XACT_STATE in some examples and while checking for state 1, i had the condition XACT_STATE >= 1 on my mind. I m updating my reply Thnx.. 
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, April 15, 2009 8:53 PM
Points: 1,
Visits: 11
|
|
Can someone direct me to where I can find a list of all the error codes returned by 'ERROR_NUMBER()' inside a stored procedure?
Thanks. Ashley
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Wednesday, July 14, 2010 10:08 AM
Points: 62,
Visits: 44
|
|
Hi,
I have a question, can i execute a insert query inside the catch block?
Regards, Arafath.
|
|
|
|