Problems Loading a Sub Report using Report Viewer control in .NET with ReportViewer.ServerReport.LoadRepo rtDefinitiion (SSRS 2005)
Hey folks, I'm having an issue with loading a Server Report using LoadReportDefinition which contains subreports. It works perfectly without a sub report. A bit of background: My report is located on a SSRS 2005 Server, and I call the GetReportDefinition() web method in my code to retrieve the report from SSRS. I then go through the report and replace certain fields in the report itself (so we can have dynamic table headers). This is all fine when there is no subreport involved. When I try to load a report which contains a subreport, it just says "Error: Subreport could not be shown " rather than displaying my subreport. Here's a snippet of code (similar to what I'm using... note that there may be some missing parts) string reportPath = "/Reports/TestWithSubReport" ; ReportingService2005 reportService; ReportParser.Report report; byte [] reportBytes; try { reportService = new ReportingService2005(); reportService.Credentials = System.Net.CredentialCache.DefaultCredentials; // Retrieve report definition from SSRS 2005 reportBytes = reportService.GetReportDefinition(reportPath); if (reportBytes != null ) { // Report object was created using xsd tool and // http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition/ XmlSerializer serializer = new XmlSerializer(typeof (ReportParser.Report)); // Load report bytes into memory stream using (MemoryStream ms = new MemoryStream(reportBytes)) { // Deserialise the report stream. report = (ReportParser.Report)serializer.Deserialize(stream); } // ... Do some magic processing stuff with the report object // ... using (MemoryStream stream = new MemoryStream()) { serializer.Serialize(stream, report); reportViewer1.ServerReport.ReportServerUrl = new Uri(@"http://localhost/reportserver" ); reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote; reportViewer1.ReportServerCredentails.NetworkCredentials = System.Net.CredentialCache.DefaultCredentials; reportViewer1.ServerReport.LoadReportDefinition(stream); reportViewer1.RefreshReport(); } } } catch (Exception ex) { //... Code to catch exception and handle it } Essentially, what I'm doing is dynamically altering a report as soon as a user requests it in our app and altering it, then loading it using LoadReportDefinition. I've thought about just altering the report when the user uploads the report (via our app) to the SSRS 2005 server, but that requires that the field names are never altered after the report has been deployed (which can not be guarenteed).
July 21st, 2010 4:24am

Hi Will3, All you described seems to be fine. Usually, the error "Error: Subreport could not be shown " occurs when one of the following conditions is ture: 1. Not all the parameters of the subreport have been assigned a value. 2. The main report has a Parameter, which allowed blank and null values. In the subreport this paramterer was linked to another parameter which did not allow nulls or blanks. In this case, if we link the parameters of the subreport to a field or a parameter in the main report, and if we change the filed or the parameter using report definition as you said, but didn't update the reference(main report -- subreport), we may encounter the issue. So, to fix the issue, please make sure all reference has been updated correctly. If you have any more questions, please feel free to ask. Thanks, Jin ChenJin Chen - MSFT
Free Windows Admin Tool Kit Click here and download it now
July 21st, 2010 11:11am

Hi Jin, I've created a new report and sub report with no parameters in the sub report and still get the same issue. So that's a bit odd.
July 29th, 2010 8:42am

Hi Will3, As you mentioned, it is a bit odd. Could you please follow these steps to troubleshoot the issue? 1. Load the main report directly without modifying the definition. 2. Check if the subreport works well. 3. Now, modify the definition without changing the subreport part. 4. Check if it works. Alternatively, if possible, could you please send us the sample reports and the sample code? I will try to reproduce the issue. You can send the files to sqltnsp AT microsoft.com(Please replace the AT with @) with the thread title and URL. Thanks, Jin ChenJin Chen - MSFT
Free Windows Admin Tool Kit Click here and download it now
July 30th, 2010 4:54am

Was there a solution found to this issue? AS I'm seeing the same results I have a report with a subreport in it. Running the report in: - VS works properly and shows the correct values in the subreport - a browser works properly and shows the correct values in the subreport Running the report through Microsoft.Reporting.WebForms.ReportViewer as a server report gives me the error Error: Subreport could not be shown
June 15th, 2011 11:13am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics