简体   繁体   English

如何增加asp.net中的服务器超时?

[英]How to increase the server timeout in asp.net?

We are using Linq to connect the database and in one situation we need to execute the big query and I can execute that query directly in sql server, but when I was trying to execute the same query through asp.net it was showing timeout error, can you help me?我们使用 Linq 连接数据库,在一种情况下我们需要执行大查询,我可以直接在 sql server 中执行该查询,但是当我尝试通过 asp.net 执行相同的查询时,它显示超时错误,你能帮助我吗?

Also we are using pagemethods => webmethods to contact the sql server.此外,我们使用 pagemethods => webmethods 来联系 sql 服务器。

http://i.stack.imgur.com/iohRx.png

You need to increase the CommandTimeout, not ConnectionTimout.您需要增加 CommandTimeout,而不是 ConnectionTimeout。 ConnectionTimeout (In other answer) is the amount of time the app allows to connect to the DB rather than run a comment. ConnectionTimeout(在其他答案中)是应用程序允许连接到数据库而不是运行评论的时间。

You probably also want to look into improving the performance of your sql query by adding indexes etc. You could use SQL profiler to catch the sql statement that Linq to SQL generated.您可能还想通过添加索引等来提高 sql 查询的性能。您可以使用 SQL 分析器来捕获 Linq to SQL 生成的 sql 语句。 Grab the query and run it through an execution plan on SSMS and see where it's taking most time to execute.获取查询并通过 SSMS 上的执行计划运行它,并查看执行时间最多的地方。 This is generally a good place to start.这通常是一个很好的起点。

Have a look at the answer to this question:Linq-to-SQL Timeout看看这个问题的答案:Linq-to-SQL Timeout

You can set the command timeout on your DataContext object ( https://msdn.microsoft.com/library/system.data.linq.datacontext.commandtimeout%28v=vs.110%29.aspx ).您可以在 DataContext 对象 ( https://msdn.microsoft.com/library/system.data.linq.datacontext.commandtimeout%28v=vs.110%29.aspx ) 上设置命令超时。

Example (from the linked answer):示例(来自链接的答案):

using (MainContext db = new MainContext())
{
    db.CommandTimeout = 3 * 60; // 3 Mins
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM