This is a migrated thread and some comments may be shown as answers.

Problem with rendering report second time

11 Answers 609 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Daniel Plomp
Top achievements
Rank 2
Daniel Plomp asked on 07 May 2011, 08:49 PM
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

11 Answers, 1 is accepted

Sort by
0
Chavdar
Telerik team
answered on 12 May 2011, 10:21 AM
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
0
Daniel Plomp
Top achievements
Rank 2
answered on 12 May 2011, 10:50 PM
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
0
Chavdar
Telerik team
answered on 13 May 2011, 10:04 AM
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
0
Daniel Plomp
Top achievements
Rank 2
answered on 16 May 2011, 12:55 PM
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");
0
Chavdar
Telerik team
answered on 17 May 2011, 05:05 PM
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
0
Fim
Top achievements
Rank 1
answered on 22 Feb 2013, 12:12 PM
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
 
0
Chavdar
Telerik team
answered on 27 Feb 2013, 02:23 PM
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!

0
Andrej
Top achievements
Rank 1
answered on 02 Mar 2015, 12:22 PM
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
















0
Andrej
Top achievements
Rank 1
answered on 02 Mar 2015, 12:35 PM
I forgot to attach a picture of error. Here it is:

0
Andrej
Top achievements
Rank 1
answered on 02 Mar 2015, 12:37 PM
I forget to attach error i get. It's in attachment.
0
Stef
Telerik team
answered on 03 Mar 2015, 09:32 AM
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.

 
Tags
General Discussions
Asked by
Daniel Plomp
Top achievements
Rank 2
Answers by
Chavdar
Telerik team
Daniel Plomp
Top achievements
Rank 2
Fim
Top achievements
Rank 1
Andrej
Top achievements
Rank 1
Stef
Telerik team
Share this question
or