Monday, July 28, 2014

SSRS Nested Subreport Gotcha!

Recently I was working on a reporting solution for a client when I ran across an interesting problem. I was writing a report in SSRS using multiple nested subreports that would roll up into the report. This has been a fairly common approach that I've used in the past. The difference in this case was the number of nested subreports. Specifically I was using three levels of reports, all of which used some form of data binding. I ran into an issue where the "grand-child" report would not render.

It is easiest to explain the situation using images. There are three reports. A top level, "master" report that we will refer to as the Parent. Within the Parent report there is a sub report that we will refer to as the Child. And within the Child report there is a sub report that we will refer to as the GrandChild.

When I initially created the report I had no issues. I was able to render the Parent, Child, and GrandChild without a problem. All of the reports bound to their respective data source and displayed the data that was expected of them. However, the moment that I added a rectangle to the Parent report, and set its "Add Page Break After" setting to True, problems arose.

With that setting checked, the GrandChild report would not render, and instead showed the error "Subreport could not be shown.".

After digging into the issue more, what I found seems to be an issue with the Child subreports data binding interfering with the GrandChild subreports data binding when the Parent subreport has the "Add Page Break After" attribute set to True on the containing element. If you need to run through that one again, don't sweat it... I had to go over it a few times before it really registered with me.

The Child subreport uses an expression to perform a lookup. Essentially this is a simple "the data source has the entity Id and we want to show the entity name" kind of lookup. If I remove this expression, the subreports return to working order.

Ultimately it turns out to be either an SSRS bug, or a limitation with the reporting framework. I've opened the following bug with Microsoft:

Whatever the deal, be careful when using nested sub reports in SSRS. If you've run into this issue before and you know of a work around, leave a comment and let me know. I'd love to be able to avoid this in the future!

No comments:

Post a Comment