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

Memory exception error on report pdf creation

9 Answers 562 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
RK
Top achievements
Rank 1
RK asked on 24 Jun 2011, 03:19 PM

I have Telerik Report that have about 700 images on it. When I generate the pdf, I get the following error message:

Here is the code that I uses.

Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("PDF", tk, null);

FileStream fs = new FileStream("d:\\report1.pdf", FileMode.Create);
fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
fs.Flush();
fs.Close();

However, when I display that in the report viewer on the screen, there is no error. Any idea on how to fix this? I have plenty of diskspace in c:/d: drives.

Thanks.

 

 

System.OutOfMemoryException was unhandled by user code
  Message=Exception of type 'System.OutOfMemoryException' was thrown.
  Source=mscorlib
  StackTrace:
       at System.IO.MemoryStream.set_Capacity(Int32 value)
       at System.IO.MemoryStream.EnsureCapacity(Int32 value)
       at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at Telerik.Reporting.Pdf.IO.PdfWriter.Write(Byte[] bytes)
       at Telerik.Reporting.Pdf.IO.PdfWriter.WriteStream(PdfDictionary value)
       at Telerik.Reporting.Pdf.PdfDictionary.WriteDictionaryStream(PdfWriter writer)
       at Telerik.Reporting.Pdf.PdfDictionary.WriteObject(PdfWriter writer)
       at Telerik.Reporting.Pdf.PdfDocument.Save(Stream stream)
       at Telerik.Reporting.ImageRendering.DocumentPdf.EndDocument()
       at Telerik.Reporting.Writing.DocumentWriter.Telerik.Reporting.Writing.IWriter.WriteEndDocument()
       at Telerik.Reporting.BaseRendering.PageHandler.Telerik.Reporting.Paging.IPageHandler.EndDocument(Boolean output)
       at Telerik.Reporting.Paging.PagerBase.AddEndDocument(Boolean output)
       at Telerik.Reporting.Paging.PageComposition.PageOverride()
       at Telerik.Reporting.Paging.PagerBase.Page(IPageHandler handler, Report report)
       at Telerik.Reporting.BaseRendering.RenderingExtensionBase.Render(Report report, Hashtable renderingInfo, Hashtable deviceInfo, CreateStream createStreamCallback, EvaluateHeaderFooterExpressions evalHeaderFooterCallback)
       at Telerik.Reporting.Processing.ReportProcessor.Render(IList`1 reports, ExtensionInfo extensionInfo, Hashtable renderingContext, Hashtable deviceInfo, CreateStream createStreamCallback)
       at Telerik.Reporting.Processing.ReportProcessor.RenderReport(String format, IReportDocument reportDocument, Hashtable deviceInfo, Hashtable renderingContext, CreateStream createStreamCallback)
       at Telerik.Reporting.Processing.ReportProcessor.RenderReportStateless(String format, IReportDocument reportDocument, Hashtable deviceInfo, Hashtable renderingContext, CreateStream createStreamCallback)
       at Telerik.Reporting.Processing.ReportProcessor.RenderReport(String format, IReportDocument reportDocument, Hashtable deviceInfo)
       at _ViewReport.rdbGo_Click(Object sender, EventArgs e) in d:\SVN\ROVCatalog\Web\ViewReport.aspx.cs:line 89
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException:

Sudanshu
Top achievements
Rank 1
commented on 20 Apr 2023, 06:13 AM

Hi ,

I am having trouble loading a lot of data records Report, and when I try to download a report in PDF format, it takes 15 minutes and fails to download with the message "Invalid Credential."

Can you give me a good solution for that

 

thanks

Todor
Telerik team
commented on 24 Apr 2023, 11:38 AM

Hi Sudanshu,

The message "Invalid Credentials" may be coming from a database server or another service. You may get the exact stack trace of the error by attaching a Trace Listener to the application hosting the Reporting engine.

Regarding the slow rendering, please, take a look at the following resources that give hints on where the problem may be coming from and how you may improve the performance:

9 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 29 Jun 2011, 02:15 PM
Hello rk,

We're aware of this problem and we're working on memory and performance optimizations for the Q2 (and would continue in Q3) release.
The fact that you use extensively images in the report, means that the memory would be increased drastically, as those images are uncompressed in memory in order to be shown in the report. You can imagine what happens if this image has to be displayed several times e.g. 700 times in your case. Also the resolution of the images plays role as well - reducing it would also reduce their size and taken up memory.

To summarize, the only way to improve the current situation is if you decrease the number of images in the reports as well as their resolution in order to minimize the chances of problems when you generate large reports.
Again we do have ideas how to improve the memory consumption and performance in general and would continue to work in this direction in next versions.

Sorry for the temporary inconvenience.

All the best,
Steve
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
vikas
Top achievements
Rank 1
answered on 04 Jul 2011, 06:19 AM
I am also getting the same error, if i try to export a large report (appx. 2000 page) without images, and once i get this error, then even if i try to export any other single page report i get the error.
To fix this issue i restart the server!

can you guys give me a better solution other than restarting the server?
0
Steve
Telerik team
answered on 05 Jul 2011, 03:52 PM
Hi Vikas,

First very important question - what format do you export to? We have tested our Reporting solution with large reports and works fairly well (by large we mean up to 1,000 pages). I have just tested with 2000 pages and the report rendered correctly in PDF (QuadCore @2.66 with 8 GB of RAM). As far as the processing time and consumed memory is concerned, the complexity of the report layout, the complexity of the data calculations (aggregates, conditional formatting),  the rendering media, the size of the generated document (in pages), and the capabilities of the underlying machine are crucial.

So you have to keep in mind that handling reports (be it with large data or large number of report items) usually requires additional resources in terms of powerful CPUs, and enough memory to handle all the operations.

Anyway as stated in previous reply, we're aware that there is much to be desired as far as memory consumption and performance goes and we're working towards this direction. In short, improving the performance of Telerik Reporting is a top priority task for us at the moment.

Thank you for the patience and understanding.

Best wishes,
Steve
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
MK
Top achievements
Rank 1
answered on 04 Oct 2011, 10:09 AM
Hi Steve,

I was wondering if there was any update to this issue? We are experiencing high memory usage on our server when carrying out a Pdf export which has substantially less than 1000 pages.

Thanks in advance.
0
IvanDT
Telerik team
answered on 07 Oct 2011, 01:00 PM
Hello Martin,

In our latest release Q2 SP1 for 2011 we have implemented our own Session State management system. Note that, Telerik Reporting session state should not be confused with the ASP.NET session state. The Telerik Reporting session state is used by all report viewers, regardless of the underlying application technology. In case of an ASP.NET web application, the Telerik Reporting session state is used to offload some large objects from the ASP.NET session state, such as rendered report pages and images, which often leads to an improved performance and a significantly reduced memory footprint for the application. You can check the following articles in our online help for more information:

  • Configuring the Database Session State Provider.

Regards,
IvanDT
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
John S.
Top achievements
Rank 1
answered on 20 Nov 2011, 11:51 PM
Hello,

I have set the Telerik.Reporting session sate to "File" and am still getting the OutOfMemoryException error. This is a serious problem when one has moved over from MSSQL Reporting Services and didn't have this problem. We are asked why we have done this. Ease of development doesn't really matter if they can't get reports.

Any suggestions?

John S.
0
Steve
Telerik team
answered on 23 Nov 2011, 05:08 PM
Hi John S.,

Without any concrete details about your reports, data and viewer you use, we cannot suggest anything. It would be best if you open a support ticket and provide us with a runnable project that exhibits the issue and we would then be able to give concrete guidance.

Greetings,
Steve
the Telerik team

Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

0
david
Top achievements
Rank 1
answered on 26 Apr 2012, 10:03 PM
I am having the same issue.  Hopefully, I can provide enough "concrete" details to help you provide a solution. 

1. I am receiving a stack trace similar to the one noted above.
2. I am passing 3000 records to the report.
3. There are 3 groups in the report.
4. I have Session State set to " file"
5. I am using reporting version 6.0.12.215 (Reporting Q1 2012)
6. The report is in landscape mode.
7. The paper size is legal

Here is the configSections of my web config:
<configSections>
        <section
               name="Telerik.Reporting"
               type="Telerik.Reporting.Processing.Config.ReportingConfigurationSection, Telerik.Reporting, Version=6.0.12.215, Culture=neutral, PublicKeyToken=a9d7983dfcc261be"
               allowLocation="true"
               allowDefinition="Everywhere"/>

etc.......

Here is the Telerik.Reporting section of my web.config file:
<Telerik.Reporting>
        <Extensions>
            <Render>
                <Extension name="PDF" description="PDF File">
                    <Parameters>
                        <Parameter name="OutputFormat" value="PDF"/>
                    </Parameters>
                </Extension>
            </Render>
        </Extensions>
        <SessionState provider="File">
            <Providers>
                <Provider name="File" type="Telerik.Reporting.Processing.Session.FileSessionProvider, Telerik.Reporting, Version=6.0.12.215, Culture=neutral, PublicKeyToken=a9d7983dfcc261be">
                    <Parameters>
                        <Parameter name="BasePath" value="App_Data\Cache" />
                    </Parameters>
                </Provider>
            </Providers>
        </SessionState>
    </Telerik.Reporting>


I have the following Reporting DLLs referenced in my project:
1. Telerik.Reporting.Adomd.dll
2. Telerik.Reporting.DatabaseSession.dll
3. Telerik.Reporting.dll
4. Telerik.Reporting.OpenXmlRendering.dll
5. Telerik.Reporting.Service.dll
6. Telerik.Reporting.XpsRendering.dll
7. Telerik.ReportViewer.WebForms.dll

So maybe we can solve this if I can better understand how the session state is supposed to work.  Here are a few questions to get started:

1. Is my web.config file set up correctly?
2. Am I missing any necessary Telerik DLLs?
3. I am not seeing anything being written to the BasePath, App_Data\Cache.  I expect that something should be written to this directory during the rendering of the pdf.  Is that the case?
4. Is there a method I can invoke to see how what type of Session State Telerik.Reporting is using?
5. Is there a maximum capacity for System.IO.MemoryStream.set_Capacity(Int32 value)?

Thank you,

David
0
Chavdar
Telerik team
answered on 01 May 2012, 02:35 PM
Hi,

The problem with the PDF rendering is that in order to generate the document all the report pages and images should be loaded simultaneously into one single memory stream. As it can become very large it may require much more memory than for example a viewer that may cache its resources through the Reporting Session State and load them on demand.

Possible solutions to the problem are to generate pdf documents with less pages or reduce the size of the images, for example by using the native for the PDF document JPEG format. You can even use a third party PDF library to join the smaller pdf files back into one large document.

We do plan to improve the performance and memory usage of the rendering extensions but at this moment there is no time estimate when it will happen as it will require a major rewrite of the extension.

Kind regards,
Chavdar
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

Tags
General Discussions
Asked by
RK
Top achievements
Rank 1
Answers by
Steve
Telerik team
vikas
Top achievements
Rank 1
MK
Top achievements
Rank 1
IvanDT
Telerik team
John S.
Top achievements
Rank 1
david
Top achievements
Rank 1
Chavdar
Telerik team
Share this question
or