I have a trouble with a report, but the strange thing it doesn't work only in production environment, if I deploy my solution on local IIS or in debugging stage with VS2013 I can see the report with subreports populated properly.
I'm using VS2013 and ReportViewer2012.
So, In developing and test environment is all ok, but in production when I invoke the print occurs this "Data retrieval failed for the subreport ... (for all subreports) ". Why?
So, I have a Report Container and within there are some subreports, and a bit code here:
Source
loadDataSources(); //loading all datatables of subreports
ReportViewer ReportViewer1 = new ReportViewer();
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.Visible = false;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/ReportContainer.rdlc");
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet0", _datatableContainer));
ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
CreatePDF(ReportViewer1, uniquefilename);
void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
if (e.ReportPath.ToLower() == "rpt_sub_1")
{
e.DataSources.Add(new ReportDataSource("DataSet1", _datatable1));
e.DataSources.Add(new ReportDataSource("DataSet2", _datatable2));
e.DataSources.Add(new ReportDataSource("DataSet3", _datatable3));
}
if (e.ReportPath.ToLower() == "rpt_sub_2")
{
e.DataSources.Add(new ReportDataSource("DataSet4", _datatable4));
e.DataSources.Add(new ReportDataSource("DataSet5", _datatable5));
e.DataSources.Add(new ReportDataSource("DataSet6", _datatable6));
e.DataSources.Add(new ReportDataSource("DataSet7", _datatable7));
}
//...
Many thanks
Ok, I fixed this problem.
The problem was the value e.ReportPath.
It was in test and development environment as this: "rpt_sub_1" or "rpt_sub_2"
but in the production environment was different : "C:\inetpub\wwwroot\MyWebSite\rpt_sub_1.rdlc" and "C:\inetpub\wwwroot\MyWebSite\rpt_sub_2.rdlc"
I fixed creating an extension method as this:
public static string CleanerReportName(this string value)
{
value = value.ToLower();
List<string> _listRemoveItems = new List<string>();
_listRemoveItems.Add(@"C:\inetpub\wwwroot\MyWebSite\");
_listRemoveItems.Add(".rdlc");
_listRemoveItems.ForEach(x => value = value.Replace(x, ""));
return value;
}
and then I modified the source as following:
void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
if (e.ReportPath.CleanerReportName() == "rpt_sub_1")
{
e.DataSources.Add(new ReportDataSource("DataSet1", _datatable1));
e.DataSources.Add(new ReportDataSource("DataSet2", _datatable2));
e.DataSources.Add(new ReportDataSource("DataSet3", _datatable3));
}
if (e.ReportPath.CleanerReportName() == "rpt_sub_2")
{
e.DataSources.Add(new ReportDataSource("DataSet4", _datatable4));
e.DataSources.Add(new ReportDataSource("DataSet5", _datatable5));
e.DataSources.Add(new ReportDataSource("DataSet6", _datatable6));
e.DataSources.Add(new ReportDataSource("DataSet7", _datatable7));
}
//...
I hope this post can help someone in the future. Bye