Skip to Content
0

Is there a maximum number of reports exports that can be generated by a user?

Apr 27 at 07:38 PM

53

avatar image

I have a windows 2012 64bit service application (built in c# VS2010, CR engine version v2.0.0.50727) that in addition to some other tasks parses text out of unstructured files, creates a Crystal Report and then automatically saves the report as PDF to disk. This process works well for about 12 hours then suddenly starts generating an error upon the call to CReport.Export(). The error is "Object Reference not set to the instance of an object.". If I switch the service account to a different user then it starts working again for about 12 hours (presumably some number of exports) and then it starts generating the error. Stopping and starting the service has no effect, the user simply can no longer call the export method. I have replicated this with the GUI calling the same bit of code. It seems that the user reaches a maximum number of report exports and then cannot export anymore reports. Below is the code (retyped for brevity) that generates the report Any help would be much appreciated!

object report = new Reports.ExportContent();
ReportDocument crReportDocument = (Reports.ExportContent)report;
crReportDocument.SetDataSource((DataTable)contentReport.Content);
Stream crIn = crReportDocument.ExportToStream(ExportFormatType.PortableDocFormat); //This call starts failing after some number of exports for the user
FileStream crOut = new FileStream(outputinfo)
//create a buffer
//write to the buffer and then to file while there is some data
//close filestream
//some error catching
//finally 
crReportDocument.Close();
crReportDocument.Dispose();
GC.Collect

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Don Williams
May 01 at 01:16 PM
0

What SP are you using? That should not happen?

Share
10 |10000 characters needed characters left characters exceeded
Don Williams
Apr 27 at 07:40 PM
0

That number is the framework, what Service Pack are you using? It's in Programs and Features and lists the actual version.

https://wiki.scn.sap.com/wiki/display/BOBJ/Crystal+Reports%2C+Developer+for+Visual+Studio+Downloads

No there is no limit but you may be running out of resources.

Why export to Stream?

Try this:

if (ExportTypeSelected == "crReportExportFormatPDF")
#region PDF
{
    // This works do not alter
    // this gets the report name and sets the export name to be the same less the extension
    string outputFileName = "";
    string MyRptName = rpt.FileName.ToString();
    outputFileName = MyRptName.Substring(9, rpt.FileName.Length - 9);
    outputFileName = outputFileName.Substring(0, (outputFileName.Length - 3)) + "pdf";

    try
    {
        if (File.Exists(outputFileName))
        {
            File.Delete(outputFileName);
        }

        CrystalDecisions.ReportAppServer.ReportDefModel.PDFExportFormatOptions RasPDFExpOpts = new PDFExportFormatOptions();

        try
        {
            RasPDFExpOpts = rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatPDF);
        }
        catch (Exception ex)
        {
            btnSQLStatement.Text = "ERROR: " + ex.Message;
            //return;
        }

        // Set them now:
        //RasPDFExpOpts.CreateBookmarksFromGroupTree = false;
        //RasPDFExpOpts.EndPageNumber = 1;
        //RasPDFExpOpts.StartPageNumber = 1;

        // Save the udpated info
        if (RasPDFExpOpts != null )
            rptClientDoc.set_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatPDF, RasPDFExpOpts);

        CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions exportOpts1 = new CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions();
        exportOpts1.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatPDF;
        exportOpts1.FormatOptions = RasPDFExpOpts;

        // And Export
        rptClientDoc.PrintOutputController.ExportEx(exportOpts1).Save(outputFileName, true);
        MessageBox.Show("Export to PDF Completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    catch (Exception ex)
    {
        btnSQLStatement.Text = "ERROR: " + ex.Message;
        return;
    }

    //// change selection formula and export again
    //rpt.RecordSelectionFormula = "{Customer.Customer Credit ID} >= 11";
    //rpt.Refresh();
    //outputFileName = outputFileName.Substring(0, (outputFileName.Length - 3)) + "1.pdf";

    //try
    //{
    //    if (File.Exists(outputFileName))
    //    {
    //        File.Delete(outputFileName);
    //    }

    //    CrystalDecisions.ReportAppServer.ReportDefModel.PDFExportFormatOptions RasPDFExpOpts = new PDFExportFormatOptions();

    //    try
    //    {
    //        RasPDFExpOpts = rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatPDF);
    //    }
    //    catch (Exception ex)
    //    {
    //        btnSQLStatement.Text = "ERROR: " + ex.Message;
    //        //return;
    //    }

    //    // Set them now:
    //    //RasPDFExpOpts.CreateBookmarksFromGroupTree = false;
    //    //RasPDFExpOpts.EndPageNumber = 1;
    //    //RasPDFExpOpts.StartPageNumber = 1;

    //    // Save the udpated info
    //    if (RasPDFExpOpts != null)
    //        rptClientDoc.set_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatPDF, RasPDFExpOpts);

    //    CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions exportOpts1 = new CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions();
    //    exportOpts1.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatPDF;
    //    exportOpts1.FormatOptions = RasPDFExpOpts;

    //    // And Export
    //    rptClientDoc.PrintOutputController.ExportEx(exportOpts1).Save(outputFileName, true);
    //    MessageBox.Show("Export to PDF Completed 2nd time", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
    //}
    //catch (Exception ex)
    //{
    //    btnSQLStatement.Text = "ERROR: " + ex.Message;
    //    return;
    //}
    // This works do not alter
    }
#endregion PDF

Don

Share
10 |10000 characters needed characters left characters exceeded
Robert Morton Apr 29 at 08:36 AM
0

Hi Don. Thanks for answering. I was actually able to figure out what was going on. Even though I was closing the report and disposing of it there were .tmp files building up in the AppData\Temp folder. For every 8 or so files that were created one would stick around. Once the number of files reached around 65K CR would no longer create temp files and presumably generate the error. I added some code to clean the .tmp files up from the Temp folder after disposal and that did the trick. Thanks again!

Share
10 |10000 characters needed characters left characters exceeded