我在我的一个页面上收到一个错误,提示 linq 查询超时,因为它花费的时间太长.它使页面无法使用.
I've been receiving an error on one of my pages that the linq query has timed out as it is taking too long. It makes the page unusable.
这是一个报告页面,管理员每天只能访问一次.根本不可避免地要缩减此查询,它只需要对大量数据进行排序即可.
It's a reports page which is only accessed by administrators around once a day. It's unavoidable to trim this query down at all, it just has to sort through a lot of data.
我读过的解决此问题的解决方案是增加数据上下文中的超时属性,但我想避免这样做,因为它会更改整个网站的设置.
Solutions to fix this I've read are by increasing the timeout property in the data context, but I'd like to avoid doing that as it would change it for the entire website.
有没有办法为单个页面设置更大的超时时间?
Is there any way to set a larger time out for individual pages?
刚刚找到答案玩智能感知:
Just found the answer playing with intellisense:
using (MainContext db = new MainContext())
{
db.CommandTimeout = 3 * 60; // 3 Mins
}
这是您可以在每个查询的基础上增加查询超时的方法,以修改连接字符串或数据上下文.
This is how you can increase the time out for a query on a per query basis as supposed to modifying the connection strings or data contexts.
这篇关于Linq-to-SQL 超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!