Click here to Skip to main content
15,668,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Friends,
In a stored procedure, I have try and catch blocks.
I do heavy calculations in try block. So sometimes I get timeout error if the data is large.
So in a catch block I rollback the transactions.
Now my question is, if the time out occurs, will the code in catch block ever execute? 
Will my transactions get rolled back?
If not, then is there any way to rollback those transactions?



First of all, it would be good if you could give me more details about your timeout error.

Sometimes CATCH blocks are bypassed (KILL command and timeout). In order to make sure that the entire transaction is terminated and rolled back, you need to add this line in your stored procedure:

Please take a look at the following link:[^]

Also, you may consider changing some timeout settings...
Share this answer
When I get this sort of thing happening I always set the timeout parameter to 0 in the connection setting.
In fact I pretty much always set the timeout setting to zero -  which basically means the connection will not time out.

You can then go about fixing slow queries after that point - my rule being that if a query takes a long time it should not cause an exception for the user.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900