T
Tim_Mac
hi,
i am encountering a sporadic exception using crystal reports that is causing
me grief, I can't 'handle' it...
my code is loading a typed report, and loading a DataSet to it.
unfortunately crystal reports customer support is very poor and their 'case
management' tool refuses to function. i'm posting here in the hope that
someone may have seen it before and worked around it.
first of all, here is the exception:
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
PEOpenPrintJobWithInfoW(* ) +0
CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String
reportName, OpenReportMethod openMethod, Int16 parentJob) +989
CrystalDecisions.CrystalReports.Engine.ReportClass.Load(String
reportName, OpenReportMethod openMethod, Int16 parentJob) +457
CrystalDecisions.CrystalReports.Engine.ReportDocument.-() +98
CrystalDecisions.CrystalReports.Engine.ReportDocument.get_DataDefinition()
+7
CrystalDecisions.CrystalReports.Engine.ReportDocument.SetParameterValue(String
name, Object value) +70
DocuSee.Report.Page_Load(Object sender, EventArgs e) +1872
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
as you can see, it is an internal CR exception, not caused directly by my
own code.
i checked all the basics, it is a perfectly valid dataset being used. also,
i don't have problems with other crystal reports using this same loading
technique.
here is my code:
Reports.crProducerApplicationForm rpt = new
Reports.crProducerApplicationForm();
rpt.SetDataSource(ds);
ExportCrystalReportToPDF(rpt, "Producer_Application.pdf");
and here is the ExportCrystalReportToPDF function
/// <summary>
/// Convert the Report to PDF and write to the HTTP response
/// </summary>
/// <param name="rpt">The report object</param>
/// <param name="filename">Should include include .pdf</param>
public static void
ExportCrystalReportToPDF(CrystalDecisions.CrystalReports.Engine.ReportClass
rpt, string filename)
{
MemoryStream stream =
(MemoryStream)rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
byte[] bytes = new Byte[stream.Length];
stream.Read(bytes, 0, (int)stream.Length);
stream.Close();
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.Buffer= true;
response.ContentType = "application/pdf";
response.AddHeader("Content-Disposition", "inline;filename=\"" + filename
+ "\"");
response.BinaryWrite(bytes);
response.End();
}
i have tested it with several different versions of acrobat, and it seems to
be completely on the server side where the error is happening. occassionally
when it does work, i have noticed incorrect download progress in the IE
status bar (when Acrobat is embedded), e.g. "downloaded 1.1Gb of 2.0Gb",
when the PDF is only a few K big.
the report itself is very simple, just displays fields and an image. it is
also 'up to date'.
it's quite a problem, so if anyone has any help, i would be extremly
grateful!
thanks
tim
i am encountering a sporadic exception using crystal reports that is causing
me grief, I can't 'handle' it...
my code is loading a typed report, and loading a DataSet to it.
unfortunately crystal reports customer support is very poor and their 'case
management' tool refuses to function. i'm posting here in the hope that
someone may have seen it before and worked around it.
first of all, here is the exception:
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
PEOpenPrintJobWithInfoW(* ) +0
CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String
reportName, OpenReportMethod openMethod, Int16 parentJob) +989
CrystalDecisions.CrystalReports.Engine.ReportClass.Load(String
reportName, OpenReportMethod openMethod, Int16 parentJob) +457
CrystalDecisions.CrystalReports.Engine.ReportDocument.-() +98
CrystalDecisions.CrystalReports.Engine.ReportDocument.get_DataDefinition()
+7
CrystalDecisions.CrystalReports.Engine.ReportDocument.SetParameterValue(String
name, Object value) +70
DocuSee.Report.Page_Load(Object sender, EventArgs e) +1872
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
as you can see, it is an internal CR exception, not caused directly by my
own code.
i checked all the basics, it is a perfectly valid dataset being used. also,
i don't have problems with other crystal reports using this same loading
technique.
here is my code:
Reports.crProducerApplicationForm rpt = new
Reports.crProducerApplicationForm();
rpt.SetDataSource(ds);
ExportCrystalReportToPDF(rpt, "Producer_Application.pdf");
and here is the ExportCrystalReportToPDF function
/// <summary>
/// Convert the Report to PDF and write to the HTTP response
/// </summary>
/// <param name="rpt">The report object</param>
/// <param name="filename">Should include include .pdf</param>
public static void
ExportCrystalReportToPDF(CrystalDecisions.CrystalReports.Engine.ReportClass
rpt, string filename)
{
MemoryStream stream =
(MemoryStream)rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
byte[] bytes = new Byte[stream.Length];
stream.Read(bytes, 0, (int)stream.Length);
stream.Close();
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.Buffer= true;
response.ContentType = "application/pdf";
response.AddHeader("Content-Disposition", "inline;filename=\"" + filename
+ "\"");
response.BinaryWrite(bytes);
response.End();
}
i have tested it with several different versions of acrobat, and it seems to
be completely on the server side where the error is happening. occassionally
when it does work, i have noticed incorrect download progress in the IE
status bar (when Acrobat is embedded), e.g. "downloaded 1.1Gb of 2.0Gb",
when the PDF is only a few K big.
the report itself is very simple, just displays fields and an image. it is
also 'up to date'.
it's quite a problem, so if anyone has any help, i would be extremly
grateful!
thanks
tim