在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();
}
}
}
在“索引”视图中,我有一个运行第二个actionresult
,即“客户”的按钮。当我尝试运行它时,它会超时。我尝试使用上面的代码将通过的参数来执行相同的存储过程,并且只需不到一秒钟的时间即可执行。似乎第一个SQL语句保持打开状态,并且不允许发送第二个(我在SQL Activity Monitor中看到了)。
出错的地方是自动生成的代码(由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);
}
最后一行,但SQL超时例外。
答案 0 :(得分:0)
您可以设置命令超时,如下所示
((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 180;//in seconds