Linq-to-SQL 超时
- 作者: 东土大唐高生
- 来源: 51数据库
- 2022-12-08
问题描述
我在我的一个页面上收到一个错误,提示 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 *****istrators 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.
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
