如何在执行时间达到**秒(SQL)时中断执行 [英] how to break execution when execution time reaches ** seconds (SQL)

查看:173
本文介绍了如何在执行时间达到**秒(SQL)时中断执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道这是否可能.
我有一个包含数十万个数据的表.
正如您已经知道的那样,
带有一堆where的select语句仍然会在至少4分钟内为我提供结果,导致我在.net屏幕上收到超时错误.

我想知道是否可以设置一个时间,例如10秒.
然后查询将在10秒后自动停止,并向我提供从第一秒到第十秒仅检索到的所有结果.
如果找到所有数据,则没有必要.只是有些会做.

谢谢.

I wonder if this is possible.
I have a table which contains hundreds of thousands of data.
And as you''ve already figured out,
having a select statement with a bunch of wheres will still give me the results in at least 4 minutes, causing me to get a timeout error on my .net screen.

I would like to know if it''s possible to set a time, say 10 seconds.
And then the query will automatically stop in 10 seconds and give me all the results that have been retrieved only from the first second to the tenth second.
It''s not necessary if it find ALL the data. Just SOME will do.

Thanks.

推荐答案

如果只是有些用",应该通过在select语句中设置ROWCOUNT或TOP来选择所需的行数.在微调查询和数据库时可获得更快的结果.

.net提供了一个取消运行查询的选项,您必须在代码中添加一个计时器,并在达到设置的超时时间后,调用SqlCommand.Cancel方法.您可以在 http://msdn.microsoft .com/en-us/library/system.data.sqlclient.sqlcommand.cancel.aspx [
You should select the needed number of rows by setting ROWCOUNT or TOP in the select statement if ''just SOME will do'' and you should be looking at fine tuning the query and database for faster results.

.net provides an option to cancel running queries, you will have to add a timer in the code and after the set timeout is reached call the SqlCommand.Cancel method. You can find the details and an example at http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.cancel.aspx[^]


这篇关于如何在执行时间达到**秒(SQL)时中断执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆