the problem
when number of users increases when printing crystal report then empty page displayed no report data loaded for all users when trying to print the report
solution workarround
1- increase the number of current print joblimit to -1
2- Unload report object in page unload event
protected void Page_Unload(object sender, EventArgs e)
{
rdoc.Close();
rdoc.Dispose();
}
3- close and dispose report after perform action for exporting pdf from report.
rdoc.Close();
rdoc.Dispose();
GC.Collect();
---------------------------------------------------------
example
//global variable
ReportDocument rdoc = new ReportDocument();
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["CurrentLanguage"].Value.ToString().IndexOf("en-") == -1)
hidLang.Value = "ar";
else
hidLang.Value = "en";
if (!Page.IsPostBack)
BindReport();
}
protected void Page_Unload(object sender, EventArgs e)
{
rdoc.Close();
rdoc.Dispose();
}
private void BindReport()
{
ConnectionInfo conInfo = new ConnectionInfo();
try
{
string stageID = "0";
DataTable table = new DataTable();
Patient_Details pdetails = new Patient_Details(db.NullToInt(Request.QueryString["patient_No"]),hidLang.Value);
string PATIENT_NAME = pdetails.PATIENT_NAME;
string Nationality = pdetails.NATIONALITY;
string Patient_Sex = pdetails.SEX;
string PatientAge = pdetails.AGE;
//if stageid is not nul this meaning that the report is printed from original workflow else it will be new version of existing one.
if (Request.QueryString["stageID"] != null)
{
stageID = Request.QueryString["stageID"].ToString();
//call stored procedure according to lang to get translated report or arabic one according to page default language.
switch (hidLang.Value)
{
case "en":
table = db.ReturnTableS("MEDICAL_REPORTS_REQUEST_SELECT_BY_REQUEST_REPORT_NO_Report_EN", "@REQUEST_REPORT_NO", Request.QueryString["rid"].ToString(), "@Patient_Name", PATIENT_NAME, "@Patient_Nationality", Nationality);
break;
default:
table = db.ReturnTableS("MEDICAL_REPORTS_REQUEST_SELECT_BY_REQUEST_REPORT_NO_Report", "@REQUEST_REPORT_NO", Request.QueryString["rid"].ToString(), "@Patient_Name", PATIENT_NAME, "@Patient_Nationality", Nationality);
break;
}
}
else
{
stageID = ((int)Enum_Class.MEDICAL_REPORTS_REQUEST_STATUS_Enum.Complete).ToString();
if (Request.QueryString["VersionID"] != null)
{
switch (hidLang.Value)
{
case "en":
table = db.ReturnTableS("MEDICAL_REPORTS_REQUEST_SELECT_BY_REQUEST_REPORT_NO_Report_EN", "@REQUEST_REPORT_NO", Request.QueryString["rid"].ToString(), "@Patient_Name", PATIENT_NAME, "@Patient_Nationality", Nationality, "@VERSION_ID", Request.QueryString["VERSIONID"].ToString());
break;
default:
table = db.ReturnTableS("MEDICAL_REPORTS_REQUEST_SELECT_BY_REQUEST_REPORT_NO_Report", "@REQUEST_REPORT_NO", Request.QueryString["rid"].ToString(), "@Patient_Name", PATIENT_NAME, "@Patient_Nationality", Nationality, "@VERSION_ID", Request.QueryString["VERSIONID"].ToString());
break;
}
}
else
Response.Write("Error In parameters Passed to the page , version not exist.");
}
if(hidLang.Value=="ar")
rdoc.Load(Server.MapPath("~\\Reports\\Reports\\Rep_MedicalReport.rpt"));
else
rdoc.Load(Server.MapPath("~\\Reports\\Reports\\Rep_MedicalReport_EN.rpt"));
rdoc.Refresh();
rdoc.SetDataSource(table);
//ParameterField p1 = new ParameterField();
//ParameterField p2 = new ParameterField();
//p1.Name = "sixty";
//certificateNo.Name = "certificateNo";
rdoc.SetParameterValue("Patient_Sex", Patient_Sex);
rdoc.SetParameterValue("stageID", stageID);
rdoc.SetParameterValue("PatientAge", PatientAge);
Draw_CVrystal();
}
catch (Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
Response.Write(ex.Message);
}
}
private void Draw_CVrystal()
{
// throw new NotImplementedException();
string MyFile;
string guidname = Guid.NewGuid().ToString("N");
MyFile = Server.MapPath(("../Reports_Print_Temp/" + (guidname + ".pdf")));
CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
ExportOptions CrExportOptions;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
DiskOpts.DiskFileName = MyFile;
CrExportOptions = rdoc.ExportOptions;
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.ExportDestinationOptions = DiskOpts;
CrExportOptions.ExportFormatOptions = CrFormatTypeOptions;
try
{
rdoc.Export();
UserLoginDetail udetail = (UserLoginDetail)Session["UserInfo"];
if (udetail != null)
{
WF_TRANSACTIONS.WORK_FLOWS_REQUESTS_PRINT_HISTORY_INSERT(((int)Enum_Class.WORKFLOWS_Enum.Medical_Report_Request).ToString(), Request.QueryString["rid"].ToString(), udetail.UserID.ToString(), DateTime.Now);
}
string docUrl = "../workflows_new/Display_Report.aspx?url=../Reports_Print_Temp/" + guidname + ".pdf";
rdoc.Close();
rdoc.Dispose();
GC.Collect();
Response.Redirect(docUrl, false);
}
catch (Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
Response.Write(("<br> the error is: " + ex.Message));
}
}
No comments:
Post a Comment