SOLVED - Out of memory exception saving large documents

Stimulsoft Reports.NET discussion
Post Reply
User avatar
poweredbyporkers
Posts: 28
Joined: Fri Nov 29, 2013 8:42 pm

SOLVED - Out of memory exception saving large documents

Post by poweredbyporkers »

I have a situation whereby I have to write each individual report out to disk and then pull them all back into single document. And yes I have to do this way even though I'd prefer not to ;-)

The problem seems to be related to SaveEncryptedDocument and SavePackedDocument. The document can be 100's of individual reports all stitched together and saves when not using either of these methods. I can't save it unencrypted or at the very least packed as they're invoices and in theory could be modified prior to printing leading to all sorts of fun and games with auditors.

So, I figure "Hey, just use a cryptostream"

This allows me to save the document, but now I can't open it as it appears the report.Load overload when using a stream calls Length and cryptostream doesn't allow seeking so it throws a 'Stream does not support seeking' exception. I've attached an example and who really appreciate some help in getting a large in-memory report to disk using encryption.

Thanks!

Example: https://www.dropbox.com/s/sqkdp2abe7air ... 7.zip?dl=0
Last edited by poweredbyporkers on Sun Nov 15, 2015 9:16 pm, edited 2 times in total.
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

Re: Out of memory exception saving large documents

Post by Ivan »

Hello,
The problem seems to be related to SaveEncryptedDocument and SavePackedDocument. The document can be 100's of individual reports all stitched together and saves when not using either of these methods.
The problem is related to images: Net Framework store images in memory in unpacked form, so for 100 Mb document file need more than 1 Gb of memory for loading.
Plus additional buffers for packing, encrypting and etc.
Therefore the SaveEncryptedDocument and SavePackedDocument commands from your sample work correctly on Win x64, but failed on Win32.

For solving this issue you need to use the report cache. It works slowly, but has a very low memory consumption.
Please modify your code:

Code: Select all

                mainReport.RenderedPages.Clear();
                mainReport.NeedsCompiling = false;
                mainReport.IsRendered = true;

                mainReport.ReportCacheMode = StiReportCacheMode.On;
                mainReport.RenderedPages.CacheMode = true;
                mainReport.RenderedPages.CanUseCacheMode = true;
Now the SaveEncryptedDocument and SavePackedDocument commands will be work without exceptions.
This allows me to save the document, but now I can't open it as it appears the report.Load overload when using a stream calls Length and cryptostream doesn't allow seeking so it throws a 'Stream does not support seeking' exception.
You can use the following code for load document from cryptostream instead of "report.LoadDocument(cryptoStream)":

Code: Select all

                var service = new StiXmlDocumentSLService();
                report.LoadDocument(service, cryptoStream);
Thank you.
User avatar
poweredbyporkers
Posts: 28
Joined: Fri Nov 29, 2013 8:42 pm

Re: SOLVED - Out of memory exception saving large documents

Post by poweredbyporkers »

Once again, thanks guys.

I was unsure about the report cache the documentation seems a little light but I knew you'd be all over it.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: SOLVED - Out of memory exception saving large documents

Post by HighAley »

Hello.

We are always glad to help you.
Let us know if you need additional help.

Thank you.
Post Reply