为什么会出现此错误 没有足够的内存资源可用于处理此命令?

Why I got this error Not enough memory resources are available to process this command?

在我的网站中使用 ASP.NET MVC + webforms C# 和 crystal 报告,

当我点击按钮打印使用 [​​=39=] 报告的报告时,我得到了这个错误

“没有足够的内存资源可用于处理此命令”

我每 2 天收到一次此错误,我通过重新发布该站点来解决它,但我需要永久解决方案

这是网络表单中使用的代码:

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
                TXTORDERID.Text = Request.QueryString["order_number"].ToString();
                TXTDEPTID.Text = Request.QueryString["deptid"].ToString();
                TXTTESTID.Text = Request.QueryString["testid"].ToString();
                TXTCULTURE.Text = Request.QueryString["Culture"].ToString();
                
                ParameterFields paramFields = new ParameterFields();
                ParameterField paramField = new ParameterField();
                ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
                ParameterDiscreteValue paramDiscreteValue1 = new ParameterDiscreteValue();
                ParameterField parameterField1 = new ParameterField();
                ParameterDiscreteValue parameterDiscreteValue1 = new ParameterDiscreteValue();
                ParameterFields parameterFields = new ParameterFields();


                if (Convert.ToInt32(TXTDEPTID.Text) == 7 && Convert.ToInt32(TXTCULTURE.Text) == 1)
                {
                    TXTPOSITIVE.Text = Request.QueryString["Positive"].ToString();
                }
                if (Session["UserCustid"] != null && Convert.ToInt32(Session["UserCustid"]) > 0)
                {
    if (Convert.ToInt32(TXTDEPTID.Text) == 1 || Convert.ToInt32(TXTDEPTID.Text) == 2 || Convert.ToInt32(TXTDEPTID.Text) == 3 || Convert.ToInt32(TXTDEPTID.Text) == 4)
                        {
    
                            paramField.Name = "@ORDER_ID";
                            paramDiscreteValue.Value = TXTORDERID.Text.ToString();
                            paramField.CurrentValues.Add(paramDiscreteValue);
                            paramFields.Add(paramField);
    
                            paramField = new ParameterField(); // <-- This line is added
                            paramDiscreteValue = new ParameterDiscreteValue();  // <-- This line is added
                            paramField.Name = "@branch_id";
                            paramDiscreteValue1.Value = TXTDEPTID.Text.ToString();
                            paramField.CurrentValues.Add(paramDiscreteValue1);
                            paramFields.Add(paramField);
    
                            CrystalReportViewer1.ParameterFieldInfo = paramFields;
                            CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
                            CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
                            reportDocument.Load(Server.MapPath("~/RPT/RPTCREDITRESULTS.rpt"));
                            CrystalReportViewer1.ReportSource = reportDocument;
                            reportDocument.SetDatabaseLogon("admin", "1234");
                            var connectionInfo = new ConnectionInfo();
                            connectionInfo.ServerName = "desktop";
                            connectionInfo.DatabaseName = "DBA";
                            connectionInfo.Password = "1234";
                            connectionInfo.UserID = "admin";
                            connectionInfo.Type = ConnectionInfoType.SQL;
                            connectionInfo.IntegratedSecurity = false;
                            for (int i = 0; i < CrystalReportViewer1.LogOnInfo.Count; i++)
                            {
                                CrystalReportViewer1.LogOnInfo[i].ConnectionInfo = connectionInfo;
                            }
    
                            CrystalReportViewer1.Dispose();
                            
                        }
                        
    
                        if (Convert.ToInt32(TXTDEPTID.Text) == 0)
                        {
    
                            parameterField1.Name = "@ORDER_ID";
                            parameterDiscreteValue1.Value = (object)this.TXTORDERID.Text.ToString();
                            parameterField1.CurrentValues.Add((ParameterValue)parameterDiscreteValue1);
                            parameterFields.Add(parameterField1);
    
                            //ParameterField parameterField2 = new ParameterField();
                            //ParameterDiscreteValue parameterDiscreteValue2 = new ParameterDiscreteValue();
                            //parameterField2.Name = "@deptid";
                            //parameterDiscreteValue2.Value = (object)this.TXTDEPTID.Text.ToString();
                            //parameterField2.CurrentValues.Add((ParameterValue)parameterDiscreteValue2);
                            //parameterFields.Add(parameterField2);
                            this.CrystalReportViewer1.ParameterFieldInfo = parameterFields;
                            this.CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
                            this.CrystalReportViewer1.ToolPanelView = ToolPanelViewType.None;
                            reportDocument.Load(this.Server.MapPath("~/RPT/RPTCREDITRESULTS.rpt"));
                            this.CrystalReportViewer1.ReportSource = (object)reportDocument;
                            reportDocument.SetDatabaseLogon("admin", "1234");
    
                            ConnectionInfo connectionInfo = new ConnectionInfo();
                            connectionInfo.ServerName = "desktop";
                            connectionInfo.DatabaseName = "DBA";
                            connectionInfo.Password = "1234";
                            connectionInfo.UserID = "admin";
                            connectionInfo.Type = ConnectionInfoType.SQL;
                            connectionInfo.IntegratedSecurity = false;
                            for (int index = 0; index < this.CrystalReportViewer1.LogOnInfo.Count; ++index)
                                this.CrystalReportViewer1.LogOnInfo[index].ConnectionInfo = connectionInfo;
                            CrystalReportViewer1.Dispose();
                        }

这是错误页面:

我需要你的帮助并解决这个错误并停止在服务器上接收错误?

我试图关闭并处理报告文档,但是当 运行 报告总是出现错误:对象引用未设置为实例对象错误

我将把关闭和处置的代码放在哪里,不会出现此错误

对象引用未设置为对象错误的实例?

reportDocument.Close(); 
reportDocument.Dispose(); 

我检查了这个 link 并在服务器注册表中将 Printjoblimit 的值更改为 1500 是否正确?

https://blogs.sap.com/2014/04/25/what-exactly-is-maximum-report-processing-job-limit-for-crystal-reports/

在页面加载 void 后添加此 void 希望这会解决错误:

protected void Page_Unload(object sender, EventArgs e)
 {
     if (reportDocument != null)
      {
              reportDocument.Close(); 
              reportDocument.Dispose();  
              reportDocument = null;
       }
 }

还有关于注册表中的打印作业限制参数尝试将值增加到 9000 并检查这是路径:

“HKEY_LOCAL_MACHINE\SOFTWARE\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Report Application Server\InprocServer”