C# 如何为长时间运行的查询增加 executionTimeout?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10649843/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to increase executionTimeout for a long-running query?
提问by Rakesh Devarasetti
In my application, one query takes 3 minutes to execute. I found that Default ExecutionTimeout value is 110 sec.I tried to change this to 500 (seconds) but it didn't fix my problem. Somewhere I found that setting <compilation debug="false">allows the ExecutionTimeoutproperty to be configured. However, even this didn't solve my problem.
在我的应用程序中,一个查询需要 3 分钟才能执行。我发现Default ExecutionTimeout 值为 110 sec。我试图将其更改为 500(秒),但没有解决我的问题。在某处我发现该设置<compilation debug="false">允许配置ExecutionTimeout属性。然而,即使这样也没有解决我的问题。
Does anyone know how I can increase the execution timeout for a long-running query?
有谁知道如何为长时间运行的查询增加执行超时?
回答by Davio
When a query takes that long, I would advice to run it asynchronously and use a callback function for when it's complete.
当查询需要那么长时间时,我建议异步运行它并在完成时使用回调函数。
I don't have much experience with ASP.NET, but maybe you can use AJAX for this asynchronous behavior.
我对 ASP.NET 没有太多经验,但也许您可以将 AJAX 用于这种异步行为。
Typically a web page should load in mere seconds, not minutes. Don't keep your users waiting for so long!
通常一个网页应该在几秒钟内加载,而不是几分钟。不要让您的用户等待这么久!
回答by Adil
You can set executionTimeoutin web.configto support the longer execution time.
您可以executionTimeout在web.config中设置以支持更长的执行时间。
executionTimeoutspecifies the maximum number of seconds that a request is allowed to execute before being automatically shut down by ASP.NET. MSDN
executionTimeout指定请求在被 ASP.NET 自动关闭之前允许执行的最大秒数。MSDN
<httpRuntime executionTimeout = "300" />
This make execution timeout to five minutes.
这使执行超时为五分钟。
Optional Int32 attribute.
可选的 Int32 属性。
Specifies the maximum number of seconds that a request is allowed to execute before being automatically shut down by ASP.NET.
This time-out applies only if the debug attribute in the compilation element is False. Therefore, if the debug attribute is True, you do not have to set this attribute to a large value in order to avoid application shutdown while you are debugging. The default is 110 seconds, Reference.
指定请求在被 ASP.NET 自动关闭之前允许执行的最大秒数。
仅当编译元素中的 debug 属性为 False 时,此超时才适用。因此,如果 debug 属性为 True,则不必将此属性设置为大值以避免在调试时关闭应用程序。默认值为 110 秒,参考。
回答by huMpty duMpty
Execution Timeout is 90 seconds for .NETFramework 1.0 and 1.1, 110 seconds otherwise.
.NETFramework 1.0 和 1.1 的执行超时为 90 秒,否则为 110 秒。
If you need to change defult settings you need to do it in your web.configunder <httpRuntime>
如果您需要更改默认设置,您需要在您的web.config下进行<httpRuntime>
<httpRuntime executionTimeout = "number(in seconds)"/>
But Remember:
但要记住:
This time-out applies only if the debug attribute in the compilation element is False.
仅当编译元素中的 debug 属性为 False 时,此超时才适用。
Have look at in detail about compilation Element
有详细了解编译元素
Have look at this document about httpRuntime Element
查看有关httpRuntime Element 的文档
回答by ChiaChi
in my case, I need to have my wcf running for more than 2 hours. Setting and did not work at all. The wcf did not execute longer than maybe 20~30 minutes. So I changed the idle timeout setting of application pool in IIS manager then it worked! In IIS manager, choose your application pool and right click on it and choose advanced settings then change the idle timeout setting to any minutes you want. So, I think setting the web.config and setting the application pool are both needed.
就我而言,我需要让我的 wcf 运行 2 个多小时。设置和根本不起作用。wcf 的执行时间不会超过 20~30 分钟。所以我在 IIS 管理器中更改了应用程序池的空闲超时设置然后它起作用了!在 IIS 管理器中,选择您的应用程序池并右键单击它并选择高级设置,然后将空闲超时设置更改为您想要的任何分钟。所以,我认为设置 web.config 和设置应用程序池都是需要的。
回答by Zeek2
RE. "Can we set this value for individual page" – MonsterMMORPG.
关于。“我们可以为单个页面设置这个值吗?” – MonsterMMORPG。
Yes, you can (& normally should) enclose the previous answer using the location-tag.
是的,您可以(并且通常应该)使用位置标签附上先前的答案。
e.g.
例如
...
<location path="YourWebpage.aspx">
<system.web>
<httpRuntime executionTimeout="300" maxRequestLength="29296" />
</system.web>
</location>
</configuration>
The above snippet is taken from the end of my own working web.config, which I tested yesterday - it works for me.
上面的片段取自我自己的工作 web.config 的末尾,我昨天测试了它 - 它对我有用。
回答by Wessam El Mahdy
To set timeout on a per page level, you could use this simple code:
要在每页级别设置超时,您可以使用以下简单代码:
Page.Server.ScriptTimeout = 60;
Note: 60 means 60 seconds, this time-out applies only if the debug attribute in the compilation element is False.
注意:60 表示 60 秒,此超时仅在编译元素中的 debug 属性为 False 时适用。

