Search code examples
c#asp.netasp.net-mvccrystal-reports

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


In my website using ASP.NET MVC + webforms C# and crystal reports ,

When I click button to print the report using crystal report I got this error

" Not enough memory resources are available to process this command"

every 2 days I got this error I solved it by republish the site again , but I need permanent solution

This is the Code used in webform :

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();
                        }

this is the error page :

enter image description here

I need your kind help please and solve this error and stop receive error on server ?

I tried to close and dispose the report document but when run the report always got error : object reference not set to an instance an object error

where I will put the code of close and dispose and not get this error

object reference not set to an instance an object error?

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

I checked this link and changed the value of Printjoblimit to 1500 in server registry is it correct?

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

Solution

  • Add this void after Page Load void hope this will solve the error :

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

    also about print job limit parameter in registry try to increase the value to 9000 for example and check this is the path :

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