Linq-to-SQL Timeout(Linq-to-SQL 超时)
问题描述
我在我的一个页面上收到一个错误,提示 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 超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Linq-to-SQL 超时


基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01