2017-07-26 76 views
0

我开发了一个使用Asp.Net MVC和Edmx数据库的网站,并且我在azure上发布了这个网站,而且我的数据库也是azure,并且我在网站上有一个功能,可以将excel记录上传到数据库中, Excel表格每次包含近18000条记录,每次我上传表格时,会在一段时间后抛出Timeout错误,所以我该怎么做。在Edmx上超时500错误

enter image description here

起初,我并没有使用任何命令的超时,但我在构造函数中

public ProfessionalServicesEntities() 
     : base("name=ProfessionalServicesEntities") 
    { 
     this.Database.CommandTimeout = 10000; 
     //this.Database.CommandTimeout = 0; //I tried this too. 

     //((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 3600; 
    } 

这里用这个做一些研究后 函数的代码: -

public void SaveEquipments(IEnumerable<EquipSampleEntity> collection) 
    { 
     using (ProfessionalServicesEntities db = new ProfessionalServicesEntities()) 
     { 
      string modelXml = XmlSerialization.ListToXml(collection.Where(x=>x.Type == Model).ToList()); 
      string accessoryXml = XmlSerialization.ListToXml(collection.Where(x => x.Type == Accessory).ToList()); 
      db.ImportEquipmentFile(modelXml, accessoryXml); 
     } 
    } 

这里是SP的上下文文件代码: -

public virtual int ImportEquipmentFile(string modelXml, string accessoryXml) 
    { 
     var modelXmlParameter = modelXml != null ? 
      new ObjectParameter("ModelXml", modelXml) : 
      new ObjectParameter("ModelXml", typeof(string)); 

     var accessoryXmlParameter = accessoryXml != null ? 
      new ObjectParameter("AccessoryXml", accessoryXml) : 
      new ObjectParameter("AccessoryXml", typeof(string)); 

     return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("ImportEquipmentFile", modelXmlParameter, accessoryXmlParameter); 
    } 
+0

增加规定时间进行处理 – jamiedanq

+0

@jamiedanq怎么样? – Abhay

+0

你可以显示你正在使用的文件上传,web.config和数据上下文(如果存在)的代码?超时前已经过了多少次?另外,我想知道是否为'ObjectContext.CommandTimeout'分配了一些值。 –

回答

0

您可能正在处理上载本身并逐行处理它的excel。您有两种选择,一种是安排后台作业来获取上传文件并将其插入数据库并完成请求。

下一个选项是一次读取整个文件,并将一个批量插入到数据库中。

+0

其实我将xml传递给我的存储过程,它将xml作为参数,然后使用openxml将数据插入到数据库中。 – Abhay

0

有太多的东西可以导致这种情况。在Azure App Service中,有一个前端具有240秒的超时时间。如果你的应用程序需要更多时间,那么你可能会遇到这个问题。这可能是可能的原因之一。

为了了解发生了什么。启用Web服务器日志记录失败的请求跟踪

Diagnostic logs

如何进一步开展看到这个:​​

+0

这不起作用 – Abhay

+0

什么是不工作。你能添加更多细节吗? –