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 超时
基础教程推荐
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
