【问题标题】:Why data retrieval failed with subreport Error with Microsoft ReportViewer?为什么数据检索失败并出现 Microsoft ReportViewer 的子报表错误?
【发布时间】:2016-06-24 15:12:45
【问题描述】:

我的报告有问题,但奇怪的是它仅在生产环境中不起作用,如果我在本地 IIS 上部署我的解决方案或在使用 VS2013 的调试阶段,我可以看到带有正确填充子报告的报告。

我正在使用 VS2013 和 ReportViewer2012。

所以,在开发和测试环境中一切正常,但在生产中,当我调用打印时,会出现“子报表的数据检索失败......(对于所有子报表)”。 为什么?

所以,我有一个报告容器,里面有一些子报告,还有一些代码:

来源

    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));
        }
        //...

非常感谢

【问题讨论】:

    标签: asp.net-mvc reporting rdlc reportviewer


    【解决方案1】:

    好的,我解决了这个问题。

    问题在于 e.ReportPath 的值。

    它在测试和开发环境中是这样的: “rpt_sub_1”或“rpt_sub_2”

    但在生产环境中有所不同: "C:\inetpub\wwwroot\MyWebSite\rpt_sub_1.rdlc" 和 "C:\inetpub\wwwroot\MyWebSite\rpt_sub_2.rdlc"

    我修复了这样创建扩展方法:

        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;
        }
    

    然后我将源代码修改如下:

        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));
            }
            //...
    

    我希望这篇文章可以在将来对某人有所帮助。 再见

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多