When you are using the Windows client for Microsoft Dynamics NAV and run a report the dataset is built by the server and piped across the network to your client. Your client then renders the dataset into the tables, images, charts etc. on your report.
If you are running a particularly data-intensive report or a report for a lot of records e.g. an invoice report for hundreds of invoices the dataset can become too large for the server / client to handle. In which case you’ll see this message:
System.OutOfMemoryException. Great. What are you supposed to do about that?
Basically you need to reduce the amount of data that needs to be passed between the server and the client. For example, if you passing a lot of rows to the report but only ever displaying the totals you could calculate the totals in the dataset designer and only pass the results to the report.
Before you start going going through your dataset with a fine-toothed comb check if you are passing any images from the dataset to the report e.g. the Picture field from Company Information. If you are, you might be passing it in every record of the dataset. View the dataset with Help, About this Report from the report preview.
BLOB fields (which images are generally stored in) which show as asterisks in the dataset viewer.
Got an asterisk in every row? That means your picture is being passed for every row in the dataset – greatly inflating the size of the dataset and making it more likely you’ll encounter the System.OutOfMemoryException.
Asterisks = evil.
Is the picture different in different rows of the dataset or is it always the same picture?
If the latter, you only need pass it once. Create a global boolean variable e.g. “LogoOutput” and add some code like the below in the first dataitem of the report:
IF LogoOutput THEN
LogoOutput := TRUE;
This will ensure that the picture isn’t passed in more rows than it has to be. Your image control then needs to know which record of the dataset to find the actual image in, like this:
i.e. regardless of whatever grouping you have in the dataset, always fetch the picture from the first record in the dataset.
Not only will this avoid the out of memory exception, but you should also notice your reports loading the rows faster (watch the progress of “Rows received” while the report is running).