OutOfMemoryException when printing an RDLC report

I have been writing quite some posts lately .. a bit too much "announcements" imho. Let's provide some content ;°). It's something we ran into lately, of which I had trouble to find solutions for.. so perfect as a blogpost.

It's about a possible error when printing an RDLC report. This is the Dutch/English version of the error message - it's the Englisch part which is most interesting:

It comes down to: "not enough memory .. printing the report has failed .. do something about it!". When you look at the Task Manager, you'll see the client's memory usage raising to a huge amount (+1,5 Gb) .. and eventually result into a crash.

When you start looking for answers, you find posts where people have this problem as well .. with a report of many many pages. We were only printing about 15 invoices in one go .. sometimes only 5 invoices and this error appeared.

First reaction: this is due to customization.
Wrong: also the default report 206 had this problem.

Second reaction: let's try it out with the latest build.
Result: none

Eh? So what was your solution?

In my case, the problem was the bitmap in table "Company Information".

If you take into account how a dataset is generated, and how RDLC is using this dataset .. then it all makes sense. Consider this:

  • You want to print 10 documents
  • Each document has 10 lines
  • In our case, each line has about 4 sub lines (like Item Texts for that Invoice line, ...).
  • The size of your picture in your Company information table is 2Mb.
  • You want to show the picture on your report (logo)

This means:

  • Roughly taken, you'll have about 400 lines in your dataset
  • Each line will have that picture incorperated.

This means:

You'll have a dataset of 800Mb for an about-20-page (probably less) report.

What if we don't need that picture?

The picture is the killer (at least in our case). We didn't even need that picture, so our developer removed it from the RDLC design. But that is not enough! You have to make sure the "CALCFIELDS" doesn't happen anymore, so the picture is not actually IN that dataset anymore. The easiest way to do that, is your setting in the Sales & Receivables Setup:

No Logo will prevent you for "calculating" the picture (or better: getting that blob out of that field..)! Another way is to remove the code on the report, of course. Personally, I was never a fan of things like that setting .. who takes that setting into account on an actually used report? Document reports are custom for each customer .. so why a general setting for something that needs customization anyway.. .

Don't know if I make any sense though ;°).

What if we do need that picture?

Well .. just know what you're doing. There are probably numerous ways to solve it.

For starters: don't import a high-definition bitmap of multiple megabytes in the Company information. Trust me, your report will look just fine when you downgrade your image a few megabytes.. .

Or try to work around the picture-in-all-lines-of-the-dataset issue. This can be done, you know. Just from the top of my head:

  • you can split the dataset. Well, not really working with multiple datasets, but still, you can do a similar thing with a simple trick. If you want, I can dedicate a blogpost on that (drop me a comment)
  • You can work with an embedded picture
  • ... I'm sure there are other neat tricks (also: drop me a comment ;°) ).

Anyway .. hope it's useful for you!

Comment List
  • Thanks for both possibilities to solve the issue .. I'll try to provide a few more in one of my next blog posts .. :-).

  • Thanks Waldo. I would be interested in any further information you could provide.

    I ran into a similar situation recently in which a customer required a statement which would require a number of logos. The statement lines were grouped by a dimension value and each group header had a different logo. I ended up solving that by having a report run by the user (in which they set the statement filters) in turn run the actual statement once for each customer. So this created many documents from many smaller datasets, rather than many documents from a single large dataset.

  • Wouldn't a simple clear on the blob field on the following dataitem (lets assume its sales line) be enough to have the picture only on the first row?

  • I will .. but can't promise when ;-)

  • Hi.

    I would be interested in your simple trick with multiple datasets.

    Can you post it?