Handling Timeouts inside stored procedures

后端 未结 4 1797
忘掉有多难
忘掉有多难 2020-12-18 16:43

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 th

相关标签:
4条回答
  • 2020-12-18 17:23

    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.

    0 讨论(0)
  • 2020-12-18 17:27

    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.

    0 讨论(0)
  • 2020-12-18 17:37

    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

    0 讨论(0)
  • 2020-12-18 17:48

    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.

    0 讨论(0)
提交回复
热议问题