Create the report once, store it in a Session variable and retrieve it on each Postback.this is working absultely fine when I am assigining object from session incase of postback but when I am trying to destoy crystal report object im page unload it is giving error - Object reference not set to an instance of an object.
If I am not destrying object it is working fine but I am geeting {"The maximum report processing jobs limit configured by your system administrator has been reached."} after running report for some time.
Please see my code givien below.
1) on this aspx page I am getting param values from session.
2) I am calling database proce and getting data into dataset.
3) If report is loading first time I am connecting db and getting value and showing report and storing crystal report obect in session.
4) onclick next page during pagination of crystal report retriewing report object from session and assiging to cryreport object.
This senario is working fine , in case of if am not closing destroying object in pageunload event.
To resove 'The maximum report processing jobs limit configured by your system administrator has been reached.' Want to close /clear crystal report object.
Please guide meu2026
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.IO;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using JLP.IRSReports.GenerateReport;
using System.Collections;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
public partial class ShowReport : System.Web.UI.Page
{
public ReportDocument cryRptDoc = new ReportDocument();
public String REPORTPATH;
string ReportName;
string BranchCode;
string BranchName;
string Month;
string Year;
protected void Page_Load(object sender, EventArgs e)
{
REPORTPATH = System.Configuration.ConfigurationManager.AppSettings["ReportPath"];
ReportName = (string)Session["ReportName"];
// ReportName = Request.QueryString["RN"];
BranchCode = (string)Session["BranchCode"];
BranchName = (string)Session["BranchName"];
Month = (string)Session["month"];
Year = (string)Session["year"];
if (!IsPostBack)
{
ShowReports(true);
}
else
{
ShowReports(false);
}
}
public void ShowReports(bool ChangeSource)
{
// ReportDocument cryRptDoc = new ReportDocument();
string ReportFullPath = REPORTPATH + ReportName + ".rpt";
using (StreamWriter sw = File.CreateText(ReportName)) { }
if (!File.Exists(ReportFullPath))
{
Response.Write("File Path is incorrect");
return;
}
// if source is not changed then show the report from the cache.
if (!ChangeSource)
{
cryRptDoc = (ReportDocument)Session["oRptSID"];
rptViewer.ReportSource = cryRptDoc;
rptViewer.HasRefreshButton = false;
rptViewer.HasCrystalLogo = false;
rptViewer.HasToggleGroupTreeButton = false;
rptViewer.HasSearchButton = false;
rptViewer.HasZoomFactorList = false;
rptViewer.HasToggleGroupTreeButton = false;
rptViewer.HasDrillUpButton = false;
return;
}
// if source is changed then regenerate the report
string month = String.Equals("Select", Month) ? null : Month;
string ReportTitle = "Criteria : Branch is " + (BranchName).Trim() + " and Year is " + Year;
cryRptDoc.Load(ReportFullPath);
cryRptDoc.SummaryInfo.ReportTitle = ReportTitle;
if (ChangeSource)
{
DataSet dsRpt = new DataSet();
GenerateReport genRpt = new GenerateReport();
dsRpt = genRpt.GetReportData(ReportName, BranchCode, int.Parse(Year), month);
cryRptDoc.SetDataSource(dsRpt.Tables[0]);
Session["oRptSID"] = cryRptDoc;
}
else
{
cryRptDoc = (ReportDocument)Session["oRptSID"];
}
rptViewer.ReportSource = cryRptDoc;
rptViewer.HasRefreshButton = false;
rptViewer.HasCrystalLogo = false;
rptViewer.HasToggleGroupTreeButton = false;
rptViewer.HasSearchButton = false;
rptViewer.HasZoomFactorList = false;
rptViewer.HasToggleGroupTreeButton = false;
rptViewer.HasDrillUpButton = false;
rptViewer.DisplayGroupTree = false;
}
protected void Page_Unload(object sender, EventArgs e)
{
if (IsPostBack)
{
cryRptDoc.Close();
cryRptDoc.Dispose();
}
}
}