LINQ到SQL超时 [英] Linq-to-SQL Timeout

查看:432
本文介绍了LINQ到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到SQL超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆