简体   繁体   English

第二个存储过程中的asp.net实体框架存储过程错误

[英]asp.net entity framework stored procedure error on second stored procedure

In ASP.NET MVC I have this controller: 在ASP.NET MVC中,我具有以下控制器:

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using test.DB;
using test.EFView;

namespace test.Controllers
{
    public class OrderAndDDTController : Controller
    {

        // GET: OrderAndDDT
        public ActionResult Index(DateTime? Start, DateTime? End)
        {
            if (Start != null && End != null)
            {
                using (var db = new PROVA_ETLEntities())
                {
                    ViewBag.Start = Start;
                    ViewBag.End = End;
                    var list = db.ddsp_getFamQty_FI(Start, End).OrderBy(x => x.Famiglia).ToList();
                    return View(list);
                }
            }

            return View();
        }

        public ActionResult Customer(DateTime? Start, DateTime? End, string Famiglia)
        {
            if (Start != null && End != null)
            {
                using (var db = new PROVA_ETLEntities())
                {
                    ViewBag.Start = Start;
                    ViewBag.End = End;
                    ViewBag.Famiglia = Famiglia;
                    var list = db.ddsp_getFamCustQty_FI(Start, End, Famiglia).OrderBy(x => x.Cliente).ToList();
                    return View(list);
                }
            }

            return View();
        }
    }
}

In the Index view I have a button that run the second actionresult , "Customer". 在索引视图中,我有一个运行第二个操作actionresult “客户”的按钮。 When I try to run it, it goes in timeout. 当我尝试运行它时,它会超时。 I try the same stored procedure with the parameters that the code above will pass, and it takes less then one second to execute. 我尝试使用上面的代码将通过的参数来执行相同的存储过程,并且只需不到一秒钟的时间即可执行。 It seems that the first SQL statement remain opening and will not allow to send the second (I see it in SQL Activity Monitor). 似乎第一个SQL语句保持打开状态,并且不允许发送第二个(我在SQL Activity Monitor中看到了)。

The point that goes in error it's the autogenerate code (By Entity Framework) and is this 错误的地方是自动生成的代码(由Entity Framework提供),这是

public virtual ObjectResult<ddsp_getFamCustQty_Result> ddsp_getFamCustQty_FI(Nullable<System.DateTime> dateStart, Nullable<System.DateTime> dateEnd, string family)
{
    var dateStartParameter = dateStart.HasValue ?
        new ObjectParameter("dateStart", dateStart) :
        new ObjectParameter("dateStart", typeof(System.DateTime));

    var dateEndParameter = dateEnd.HasValue ?
        new ObjectParameter("dateEnd", dateEnd) :
        new ObjectParameter("dateEnd", typeof(System.DateTime));

    var familyParameter = family != null ?
        new ObjectParameter("family", family) :
        new ObjectParameter("family", typeof(string));

    return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<ddsp_getFamCustQty_Result>("ddsp_getFamCustQty_FI", dateStartParameter, dateEndParameter, familyParameter);
} 

on the last row, with SQL timeout exception. 在最后一行,但SQL超时异常。

您可以设置命令超时,如下所示

   ((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 180;//in seconds

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM