views:

32

answers:

4

I have a stored procedure that executes a couple of queries. Each query might fail because of a timeout.

I still want to continue to execute the other queries. Is this possible? Does a try catch work for timeouts?

I can offcourse have different sps for each query, but that would make the application more complex.

+2  A: 

How you run the SQL?

SQL itself has no timeout, so what you describe as a problem is not possible.

The timeout is always handled on the connection level / connecting application. SQL Server is happy having SQL calls that last for hours or days.

So, unless you do sometihing "funny" / unusual the queries within the SP will not time out - the connection that calls the procedure will time out and thus rollback the transaction.

TomTom
+1  A: 

The queries within Stored Procedures don't time out - the sql batch that is executing the sproc times out - so no, you can't 'catch' and then handle timeouts.

Will A
A: 

Short answer: no. Timeout is just like when you cancel your query in SSMS: CATCH won't catch it. I wrote up a canned answer: Your TRY block may fail, and your CATCH block may be bypassed

AlexKuznetsov
A: 

If you are frequently getting timeouts, the fix is to performance tune the queries not to try to skip the timeouts and move onto the next query.

Timeouts are usually a sign of bad query design (Number 1 cause), bad database design (number 2 cause) or inadequate equipment. All three are fixable. So fix them.

HLGEM