I'm using the ReportProcessor class in order to export reports in an HTML format progmmatically. I have a couple of questions; I'm about at wit's end, here.
I have a report which contains a sub report. Each of these reports is encapsulated in a TRDX file. I create an instance of the main report (let's call it MainReport), which is of type Telerik.Reporting.Report. I get a reference to MainReport's DataSource property, which is a SqlDataSource, and I set the ConnectionString property to a connection string in my app.config file. I then instantiate an InstanceReportSource and set the ReportDocument property to my MainReport object. At this point, I can render the main report via the ReportProcessor.RenderReport method. All is well and good so far.
My problem is with the sub report. What do I need to do to include it? I've looked at the limited amount of documentation over and over but I simply cannot wrap my head around what I need to do. Here's what almost works:
I create an instance of the sub report the same way I'm instantiating MainReport (we'll call it SubReport). I then Find() the sub report item within MainReport's Items collection, and after grabbing that reference, I set its ReportSource property to my SubReport instance.
Here's the problem with that: Apparently this way of doing things is obsolete. I need to know how to do it correctly. Also, I need SubReport.DataSource.ConnectionString to be the same as MainReport.DataSource.ConnectionString. Additionally, there is a Crosstab item within the main report that apparently also needs a ConnectionString, even though the DataSource is the same as MainReport's DataSource.
Here's some code snippets:
//MainReport instantiation (some code is hidden, but you should get the idea
XmlReaderSettings xmlReaderSettings =
ReportXmlSerializer serializer =
XmlReader primaryReportXmlReader = XmlReader.Create(reportDefinition.PrimaryReport.TemplateLocation, xmlReaderSettings);
_primaryReport = (Telerik.Reporting.Report)serializer.Deserialize(primaryReportXmlReader);
SqlDataSource reportDataSource = (SqlDataSource)_primaryReport.DataSource;
reportDataSource.ConnectionString = reportDefinition.ConnectionString;
._instanceReportSource.ReportDocument = _primaryReport;
//We're using a custom class to define a "report definition", which contains data about sub reports,
//so I'm looping through each sub report definition and instantiating it.
XmlReader xmlReader = XmlReader.Create(cpsSubReport.TemplateLocation, xmlReaderSettings);
Telerik.Reporting.Report subReportInstance = (Telerik.Reporting.Report)serializer.Deserialize(xmlReader);
SqlDataSource subReportDataSource = (SqlDataSource)subReportInstance.DataSource;
subReportDataSource.ConnectionString = reportDefinition.ConnectionString;
//would be handy to automatically get from the main report
//The following line is hardcoded for now because i've been experimenting. The string "subReport1" would actually be defined in our custom report definition class.
Telerik.Reporting.SubReport subReport = _primaryReport.Items.Find(
subReport.ReportSource = subReportInstance;
//obsolete. what's the right way to do this?
Also, as I mentioned, in the rendered report, I get an error about the Crosstab connection string:
An error has occurred while processing Table 'crosstab2': Unable to establish a connection to the database. Please, verify that your connection string is valid. In case you use a named connection string from the application configuration file, make sure the name is correct and the connection string settings are present in the configuration file of your application. ------------- InnerException ------------- Format of the initialization string does not conform to specification starting at index 0.
Please help? :)