Problem with rendering report second time

12 posts, 0 answers
  1. Daniel Plomp
    Daniel Plomp avatar
    7 posts
    Member since:
    Jun 2012

    Posted 07 May 2011 Link to this post

    Hi,

    I've created a webshop in Sitefinity. When a user finishes the order, a .pdf invoice file is send.
    The first time this process goes without any problem.

    The second time, the rendered .pdf is empty. I notice that creating a new instance of the report is very fast, the second time, so it looks like it is not creating a new, fresh instance.

    This is the code I'm using:
    /// <summary>
        /// Generate an invoice
        /// </summary>
        private Attachment GenerateInvoice(Guid orderid, string ordernumber, string att, string address, string att2, string address2) {
            try {
     
                rptInvoice report = new rptInvoice();
                Filter f = new Filter();
                f.Expression = "=Fields.OrderId";
                f.Operator = FilterOperator.Equal;
                f.Value = orderid.ToString();
                report.Filters.Add(f);
     
                // Invoice address
                report.Att = att;
                report.FullAddress = address;
     
                // Send address
                report.Att2 = att2 != string.Empty ? "VERZENDADRES:" + Environment.NewLine + att2 : string.Empty;
                report.FullAddress2 = address2;
     
                ReportProcessor processor = new ReportProcessor();
                RenderingResult result = processor.RenderReport("PDF", report, null);
     
                string reportName = "Factuur-" + ordernumber + ".pdf";
                string reportLocation = MapPath("~/Orders/");
     
                using (FileStream fs = new FileStream(reportLocation + reportName, FileMode.Create)) {
                    fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
                    fs.Close();
                    fs.Dispose();
                }
                 
                report.Dispose();
                processor = null;
                result = null;
     
                return new Attachment(reportLocation + reportName);
            }
            catch (Exception ex) {
                throw ex;
            }
        }

    When I restart the webserver, or kill wp3 I can generate my invoices correctly...

    What could this be?

    Regards,
    Daniel
  2. Chavdar
    Admin
    Chavdar avatar
    898 posts

    Posted 12 May 2011 Link to this post

    Hello Daniel,

    After reviewing your code I think there could be two reasons for the problem.

    1. As you are using a Filter expression it might happen that when applied the filtered result contains no data. To check this case simply hard code an ordernumber for which you are sure there is certain data and try to generate the invoice for a second time. It should be as the first one.

    2. If the first suggestion fails, try to generate the PDF files with random names as it might happen that the previous file is somehow locked and cannot be overwritten.

    For sure the problem is not with the ReportProcessor.Render method as it is not aware how many times it is called. Still, we cannot debug your running application in order to determine the exact reason for the problem and these are just suggestions. If you are able to put a break-point in your code or a trace it will give you much more details about what happens.

    Regards,
    Chavdar
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Daniel Plomp
    Daniel Plomp avatar
    7 posts
    Member since:
    Jun 2012

    Posted 12 May 2011 Link to this post

    Hi Chavdar,

    Thanks for your reply.
    Regarding your suggestions:

    1. As you are using a Filter expression it might happen that when applied the filtered result contains no data. To check this case simply hard code an ordernumber for which you are sure there is certain data and try to generate the invoice for a second time. It should be as the first one.
    - The ordernumbers are generated when placing an order. I cannot give a hardcoded. Each order should be having a different ordernumber.

    2. If the first suggestion fails, try to generate the PDF files with random names as it might happen that the previous file is somehow locked and cannot be overwritten.

    Files are never overwritten as they always have unique names

    Regards,
    Daniel
  4. Chavdar
    Admin
    Chavdar avatar
    898 posts

    Posted 13 May 2011 Link to this post

    Hi Daniel Plomp,

    These were my only suggestions based on the code snippet you have sent. Everything else seems to be correct so you have to search for the problem somewhere outside this method. What I can assure you is that this is not a bug in the reporting engine. If you need further assistance please give us some more details about your system or open a support ticket and send us a sample project that replicates the problem.

    Regards,
    Chavdar
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Daniel Plomp
    Daniel Plomp avatar
    7 posts
    Member since:
    Jun 2012

    Posted 16 May 2011 Link to this post

    Hi Chadvar,

    Yes, I know. Thanks for the suggestions!
    I followed suggestion number 1 and if I hard-code the OrderId it renders the .pdf correctly.

    So, when programmatically setting the filter it goes wrong. The second time the .pdf is completely empty.
    I cannot discover what is going wrong. Could it be something with the ORM layer? I use an OpenAccess datasource and my website is also referring to the same model.

    By the way the public properties that I created on the report itself are being set from my code. So that seems to work okay. Only the filter is a problem.

    Caching or something?

    Regards,
    Daniel

    PS: changed the code to the following:
    rptInvoice report = new rptInvoice();
               report.Filters.Clear();
     
               Filter f = new Filter();
               f.Expression = "=Fields.OrderId";
               f.Operator = FilterOperator.Equal;
               f.Value = orderid.ToString();
               report.Filters.Add(f);
     
               // Give a reportname and documentname based on suggestion of Telerik
               string reportName = "factuur-" + ordernumber.ToString();
               report.Name = reportName;
               report.DocumentName = reportName;
     
               // Invoice address
               report.Att = att;
               report.FullAddress = address;
     
               // Send address
               report.Att2 = att2 != string.Empty ? "VERZENDADRES:" + Environment.NewLine + att2 : string.Empty;
               report.FullAddress2 = address2;
     
               ReportProcessor processor = new ReportProcessor();
               RenderingResult result = processor.RenderReport("PDF", report, null);
                
               string reportLocation = MapPath("~/Orders/");
     
               using (FileStream fs = new FileStream(reportLocation + reportName  + ".pdf", FileMode.Create)) {
                   fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
                   fs.Close(); // obsolete, I think)
                   fs.Dispose(); // obsolete, I think)
               }
                
               // Really nessecary?
               report.Dispose();
               report = null;
               processor = null;
               result = null;
               f = null;
     
               return new Attachment(reportLocation + reportName + ".pdf");
  6. Chavdar
    Admin
    Chavdar avatar
    898 posts

    Posted 17 May 2011 Link to this post

    Hi Daniel,

    Telerik Reporting does not cache any data so this could not be the problem. Please, check whether your data source holds the necessary data. For this purpose, create a simple report without any filters which shows one OrderId per row and use it in this method to debug.

    Best wishes,
    Chavdar
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Fim
    Fim avatar
    11 posts
    Member since:
    Oct 2012

    Posted 22 Feb 2013 Link to this post

    Hi,

    I know this is an old thread, but i am also facing the same issue. The first time the report renders correctly to PDF. then second time it is blank. No errors are thrown and i have tried all the suggestions mentioned in this thread.
    Following is the code for returning the bytes. What i have found during debugging, the bytes returned at different the first time and the subsequent times though the data for the report is returned correctly both times
    Byte[] bytes = null;
    Telerik.Reporting.Report reportToPDF = null;
    try
    {
    // Calling the required report here
    reportToPDF = DSReport;

    Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
    Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
    instanceReportSource.ReportDocument = reportToPDF;
    Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);
    bytes = result.DocumentBytes;

    }
    catch (Exception ex)
    {
    Log.LogException(ex, "General Policy");
    }
    return bytes;

    Any advice is greatly appreciated
     
  8. Chavdar
    Admin
    Chavdar avatar
    898 posts

    Posted 27 Feb 2013 Link to this post

    Hi,

    The provided code snippet is correct and doesn't give enough information to determine the problem. In order to troubleshoot the issue we will need the report definition or a sample project that reproduces it.

    All the best,
    Chavdar
    the Telerik team

    See what's new in Telerik Reporting Q1 2013. Register for the March 4 webinar to witness the impressive new visualizations in Telerik Reporting. Just for fun, 10 webinar attendees will be randomly selected to win a Telerik T-shirt and a $50 Gift Certificate to ThinkGeek. Register now! Seats are limited!

  9. Andrej
    Andrej avatar
    3 posts
    Member since:
    Mar 2012

    Posted 02 Mar 2015 Link to this post

    Hellow.

    It's anything new on this thread?
    I have exactly the same issue. I'm using Reporting version 9.0.15.225.

    When I render the report for second time, I get a error witch is in attachment. 
    I am sure it's nothing wrong with ORM layer (Entity Framework), because printing working fine until method for saving isn't executed. When SaveReport is executed for first time everything is ok. Since then, even direct printing doesn't work anymore. If i restart application printing working again.

    Method for saving report to pdf file:
     
    void SaveReport(Telerik.Reporting.Report report, string fileName)
            {
                ReportProcessor reportProcessor = new ReportProcessor();
                Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
                instanceReportSource.ReportDocument = report;
                RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);
     
                using (FileStream fs = new FileStream(fileName, FileMode.Create))
                {
                    fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
                }
            }
    Method for direct print:
    void PrintReport(Telerik.Reporting.Report report)
            {
    .
    .
    .
         PrintController standardPrintController = new StandardPrintController();
                        ReportProcessor rp = new ReportProcessor();
                        rp.PrintController = standardPrintController;
                             
                             
                        for (int i = 0; i < printForm.NumOfCopies; i++)
                        {
                            rp.PrintReport(report, ps);
                        }
    }

    Where is the problem or what i'm doing wrong?

    Regards,
    Andrej
















  10. Andrej
    Andrej avatar
    3 posts
    Member since:
    Mar 2012

    Posted 02 Mar 2015 in reply to Andrej Link to this post

    I forgot to attach a picture of error. Here it is:

  11. Andrej
    Andrej avatar
    3 posts
    Member since:
    Mar 2012

    Posted 02 Mar 2015 in reply to Andrej Link to this post

    I forget to attach error i get. It's in attachment.
  12. Stef
    Admin
    Stef avatar
    3332 posts

    Posted 03 Mar 2015 Link to this post

    Hi Andrej,

    Below is a quote from my response in your ticket # 911773 on the same question:
    "We tested the provided code snippet in our local WpfDemo project installed by default under C:\Program Files (x86)\Telerik\Reporting Q1 2015\Examples\CSharp\WpfDemo. For each export and print operation we pass a new instance of the report e.g.,   PrintReport(new Dashboard());. The reason is to avoid issues with shared resources in case a report instance is used by the viewer and by ReportProcessor instance.

    Please test the above approach for running both operations, also verify EntityFramework references are updated correctly (assemblies, binding redirects and assembly references must point to the same version).
    "


    We requested additional information to investigate the problem, thus please let us continue the discussion in the above mentioned ticket.

    Regards,
    Stef
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top