Linq-to-SQL 超时

Linq-to-SQL Timeout(Linq-to-SQL 超时)
本文介绍了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 超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Is Unpivot (Not Pivot) functionality available in Linq to SQL? How?(Linq to SQL 中是否提供 Unpivot(非 Pivot)功能?如何?)
How to know if a field is numeric in Linq To SQL(如何在 Linq To SQL 中知道字段是否为数字)
Linq2SQl eager load with multiple DataLoadOptions(具有多个 DataLoadOptions 的 Linq2SQl 急切加载)
Extract sql query from LINQ expressions(从 LINQ 表达式中提取 sql 查询)
LINQ Where in collection clause(LINQ Where in collection 子句)
Orderby() not ordering numbers correctly c#(Orderby() 没有正确排序数字 c#)