第 XXXX 行的内存不足

本文关键字:内存不足 XXXX | 更新日期: 2023-09-27 18:19:31

谁能帮我解决ASP页面上的内存不足错误? 我使用LINQ到SQL..添加数据后几个数据..喜欢超过10行。 在网格中。 发生内存不足错误.. 随函附上我的添加函数。

public ServiceDetail checkservicedetailid()
{
    string ServiceName = ViewState["Tab"].ToString();
    ServiceDetail checkservicedetailid = ServiceDetails_worker.get(a => a.ServiceName == ServiceName && a.MarginAnalysisID == checkmarginanalysisid().MarginAnalysisID).SingleOrDefault();
    return checkservicedetailid;
}
public IEnumerable<ServiceDetail> get(Expression<Func<ServiceDetail, Boolean>> express)    
{ 
    return ServiceDetailsDB.ServiceDetails.Where(express); 
}
protected void btnSaveEmptyOC_Click(object sender, EventArgs e)
{
   try
   {
       if (checkservicedetailid() != null)
       {
           CashExpense tblCashExpenses = new CashExpense();
           Guid CashExpensesID = Guid.NewGuid();
           tblCashExpenses.CashExpensesID = CashExpensesID;
           tblCashExpenses.ServiceDetailsID = checkservicedetailid().ServiceDetailsID;
           tblCashExpenses.Description = txtDescriptionEmptyOC.Text;
           tblCashExpenses.Quantity = Decimal.Parse(txtQTYEmptyOC.Text);
           tblCashExpenses.UnitCost = Decimal.Parse(txtUnitCostEmptyOC.Text);
           tblCashExpenses.CreatedBy = User.Identity.Name;
           tblCashExpenses.DateCreated = DateTime.Now;
           tblCashExpenses.CashExpensesTypeID = "OTHER";
           CashExpenses_worker.insert(tblCashExpenses);
           CashExpenses_worker.submit();
           //Clear items after saving
           txtDescriptionEmptyOC.Text = "";
           txtQTYEmptyOC.Text = "";
           txtUnitCostEmptyOC.Text = "";
           ValidationMessage.ShowValidationMessage(MessageCenter.CashExpenseMaintenace.InsertOC2, "SaveEmptyOC", this.Page);
           MyAuditProvider.Insert(this.GetType().ToString(), ViewState["MarginAnalysisID"].ToString(), MessageCenter.Mode.ADD, MessageCenter.CashExpenseMaintenace.InsertOC2, Page.Request, User);
           divOtherCost.Visible = false;
           grd_othercost.Visible = true;
           btnaddothercost.Visible = true;
       }
       else
       {
           //Displays a Message on the Validation Summary (Service Id does not exist)
           ValidationMessage.ShowValidationMessage(MessageCenter.CashExpenseMaintenace.SaveServiceDetailOC, "SaveEmptyOC", this.Page);
       }
   }
   catch
   {
       //Displays a Message on the Validation Summary (Error on Saving)
       ValidationMessage.ShowValidationMessage(MessageCenter.CashExpenseMaintenace.InsertOCError, "SaveEmptyOC", this.Page);
   }
   finally
   {
       //Rebinds the Grid
       populategrd_othercost();
    }
}

第 XXXX 行的内存不足

我从你的代码中猜测:

ServiceDetail checkservicedetailid = ServiceDetails_worker.get(
    a => a.ServiceName == ServiceName &&
         a.MarginAnalysisID == checkmarginanalysisid().MarginAnalysisID
).SingleOrDefault();

那个.get()正在Func<SomeType, bool>,而你正在做这样的事情:

var row = dbCtx.SomeTable.Where(predicate);

(如果我不正确,请在这里纠正我(

但是,这是使用 LINQ-to-Objects,这意味着:它将表的每一行加载到客户端并在本地进行测试。这会损害内存,特别是如果为每一行创建了不同的数据库上下文。此外,checkmarginanalysisid()调用是按行执行的,而行之间可能没有变化。

您应该使用Expression<Func<SomeType, bool>>对此进行测试,该该将被转换为 TSQL 并在服务器上执行。您可能还需要删除无法翻译的方法,即

var marginAnalysisId = checkmarginanalysisid().MarginAnalysisID;
ServiceDetail checkservicedetailid = ServiceDetails_worker.get(
    a => a.ServiceName == ServiceName &&
         a.MarginAnalysisID == marginAnalysisId
).SingleOrDefault();

那是get(Expression<Func<SomeType, bool>>).

我尝试了同行提供给我的所有解决方案以及此处提供的解决方案,来自 GC。收集,在使用后处置 linq datacontext 等,但是错误不断发生,然后我尝试删除更新面板,我阅读了一个网站,该网站显示了在处理数据时更新面板是多么荒谬,尤其是当一个功能重复完成时。噗!内存问题消失了!