LINQ超时,而相同的查询在SQL中运行良好

时间:2011-01-16 15:50:29

标签: c# asp.net sql linq

 Exception of type 'System.Web.HttpUnhandledException' was thrown.
 ---> System.Data.SqlClient.SqlException (0x80131904): Timeout expired.  
 The timeout period elapsed prior to completion of the operation 
 or the server is not responding.

        var items = dataContext.function1(sid);                
        var sortBy = Int32.Parse(Request["iSortCol_0"]);
        var sortAsc = Request["sSortDir_0"] == "asc";                

        /* All items after filtering */
        var totalItems = items.Count();

        if (!String.IsNullOrEmpty(Request["iDisplayStart"]))
            items = items.Skip(Int32.Parse(Request["iDisplayStart"]));
        if (!String.IsNullOrEmpty(Request["iDisplayLength"]))
            items = items.Take(Int32.Parse(Request["iDisplayLength"]));
foreach (var cres in items)
            {
...
...

当我在SQL查询程序中运行SAME查询时,我会在几秒钟内得到结果,而在LINQ中,它会花费很长时间并失败。

是什么导致这个?

谢谢!

1 个答案:

答案 0 :(得分:0)

我重新启动了SQL Server服务及其工作。 是什么导致这个?