处理存储过程中的超时 [英] Handling Timeouts inside stored procedures
问题描述
我有一个执行几个查询的存储过程.每个查询都可能因超时而失败.
I have a stored procedure that executes a couple of queries. Each query might fail because of a timeout.
我还想继续执行其他查询.这可能吗?try catch 对超时有用吗?
I still want to continue to execute the other queries. Is this possible? Does a try catch work for timeouts?
我当然可以为每个查询使用不同的 sps,但这会使应用程序更加复杂.
I can offcourse have different sps for each query, but that would make the application more complex.
推荐答案
您如何运行 SQL?
SQL 本身没有超时,因此您描述的问题是不可能的.
SQL itself has no timeout, so what you describe as a problem is not possible.
超时总是在连接级别/连接应用程序上处理.SQL Server 很高兴有持续数小时或数天的 SQL 调用.
The timeout is always handled on the connection level / connecting application. SQL Server is happy having SQL calls that last for hours or days.
因此,除非您做了一些有趣"/不寻常的事情,否则 SP 中的查询不会超时 - 调用该过程的连接将超时,从而回滚事务.
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.
这篇关于处理存储过程中的超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!