在 SQL Server 中强制查询超时

Forcing a query timeout in SQL Server(在 SQL Server 中强制查询超时)
本文介绍了在 SQL Server 中强制查询超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们遇到了一个代码块的问题,该代码块在面对缓慢的数据库时反应不佳(它在查询超时时搞砸了床).我们已经创建了一个补丁,并且正在通过回归运行它.

We have had an issue with a block of code that responds poorly in the face of slow databases (It craps the bed on a query timeout). We have created a patch, and are in the process of running it through regression.

我们无法获得超时.我已经从 SQL Mgmt Studio 打开了一个事务并更新了每一行以锁定它们,但这不会导致 INSERT 超时(这是我需要的).

We can't get a timeout. I've opened a transaction from SQL Mgmt Studio and updated every row to lock them, but that doesn't cause INSERTs to timeout (which is what I need).

我可以通过 T-SQL 轻松获得表级锁吗?还是我必须在主人身上摆弄?或者我可以在不锁定的情况下轻松强制超时吗?任何输入表示赞赏.

Can I get a table-level lock easily via T-SQL? Or do I have to fiddle around in master? Or can I easily force the timeout without locking? Any input is appreciated.

推荐答案

运行此程序,然后尝试插入...

run this and then try your insert...

select * from yourTable with (holdlock,tablockx)

在这里,您可以将其锁定 5 分钟:

here, you can lock it for 5 minutes:

BEGIN TRANSACTION

SELECT * FROM yourTable WITH (TABLOCKX, HOLDLOCK)

WHERE 0 = 1

WAITFOR DELAY '00:05'

ROLLBACK TRANSACTION

这篇关于在 SQL Server 中强制查询超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)