超时查询 [英] Timeout a query

查看:163
本文介绍了超时查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,如果我们能够超时的SQL查询。

I wanted to know if we can timeout a sql query.

在这个意义上,即假设我有一个SQL查询的输出是唯一有用的,如果给输出10分钟后,即使它的结果的没有用的输出到我。

In the sense, that suppose I have a sql query whose output is useful only if gives the output in 10 minutes ,after which even if it outputs the results its of no use to me.

我想要做的是正中下怀,如果查询时间超过10分钟,做加工,那么它应该杀了自己。

What I want to do is that if the query takes more than 10 minutes to do the processing then it should just kind of kill itself.

有没有一种可能的方法,这样做?

Is there a possible way to do so??

这是实施例将是pretty的帮助。

An example will be pretty helpful.

让我知道,如果我的想法是不是COM prehendible ..

Let me know if my thoughts are not comprehendible..

推荐答案

下面是它会是什么样子的<一个href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout%28v=VS.100%29.aspx"相对=nofollow> SqlCommand.CommandTimeout

Here's what it would look like for the SqlCommand.CommandTimeout

   SqlCommand cmd = new SqlCommand();
   cmd.CommandText = "SELECT blah FROM Categories ORDER BY CategoryID";
   cmd.CommandTimeout = 600;  // 10 minutes = 600 seconds
   // Caveat: it you need a timeout value of more than 30 - 60 seconds
   //         perhaps time to look at why it takes so long...

这篇关于超时查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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