简体   繁体   English

我在RDLC报告中收到“报告'xxxx.rdlc'的报告定义”

[英]I'm getting “The report definition for report 'xxxx.rdlc' has not been specified” in my RDLC report

I've created an rdlc report. 我创建了一个rdlc报告。 I have a reportViewer on my form. 我的表单上有一个reportViewer。 When I try to load the report I get : "The report definition for report 'xxxx.rdlc' has not been specified". 当我尝试加载报告时,我得到:“报告'xxxx.rdlc'的报告定义尚未指定”。 I can't figure this out. 我无法弄清楚这一点。 I have a datatable with the data I need for the report. 我有一个数据表,其中包含报告所需的数据。 I take this dataTable and I load it back to my database, to a table called "FinalReport". 我把这个dataTable加载到我的数据库,然后加载到一个名为“FinalReport”的表中。 (The reason i'm doing this, is because that rdlc requires some sort of a dataSource.) I have a table inside my report (table1). (我这样做的原因是因为rdlc需要某种dataSource。)我的报告中有一个表(table1)。 This is my code (inside my form, where the report viewer is located): 这是我的代码(在我的表单中,报表查看器所在的位置):

this.finalDataReportTableAdapter.Fill(this.nehasitDataSet.FinalDataReport);
localReport.ReportEmbeddedResource = @"Resources\VisibleAssets.rdlc";
//I'm not so sure about the following line, but it's the only line that prevented me from getting an error ("no reportdefinition defined"
using (StreamReader rdlcSR = new StreamReader(@"Resources\VisibleAssets.rdlc"))
{
    localReport.LoadReportDefinition(rdlcSR);

    localReport.Refresh();
}

this.reportViewer.RefreshReport();

I also connected the report to the dataTable and the reportViewer to the report. 我还将报告连接到dataTable,将reportViewer连接到报告。 I really can't see the problem, and I searched Google for it. 我真的看不出问题,我搜索谷歌。

Any help will be highly appreciated. 任何帮助将受到高度赞赏。

There are some reasons causing this problem and sometimes the problem might occur only when publishing the same application to IIS . 导致此问题的原因有一些,有时仅在将相同的应用程序发布到IIS时才会出现问题。 If the report file (*.rdlc) is existed in the related location and the problem still continues, you can try the following methods in order to fix it: 如果报告文件(* .rdlc)存在于相关位置,问题仍然存在,您可以尝试以下方法来修复它:

from LocalReport.ReportEmbeddedResource Property on MSDN 来自 MSDN上的LocalReport.ReportEmbeddedResource属性
“… An embedded report resource is a report definition that has been stored as a resource in the calling assembly. “...嵌入式报告资源是一种报告定义,已作为资源存储在调用程序集中。 If the ReportPath property has been set, the ReportEmbeddedResource property is ignored. 如果已设置ReportPath属性,则忽略ReportEmbeddedResource属性。 It also causes the report loaded with LoadReportDefinition to be ignored.” 它还会导致加载LoadReportDefinition的报告被忽略。“

Change: 更改:

reportViewer.LocalReport.ReportPath = Server.MapPath("~/Reporting/YourReportName.rdlc");

to: 至:

rw.LocalReport.ReportEmbeddedResource = "YourFullNamespace.Reporting.YourReportName.rdlc";

And then change Build Action property to Embedded Resource from the properties of YourReportName.rdlc file. 然后从YourReportName.rdlc文件的属性将Build Action属性更改为Embedded Resource Hope this helps... 希望这可以帮助...


I was getting the same error but I'm loading my report in a different way. 我得到了同样的错误,但我以不同的方式加载我的报告。 I followed the instruction on MSDN . 我按照MSDN上的说明进行操作。 Except where they reference ReportEmbeddedResource I, instead, used ReportPath . 除非他们引用ReportEmbeddedResource I, ReportEmbeddedResource使用ReportPath When I make that change my report loads. 当我进行更改时,我的报告会加载。

public partial class ReportViewer : Page
{
    private bool _isReportViewerLoaded;

    public ReportViewer()
    {
        InitializeComponent();
        _reportViewer.Load += _reportViewer_Load;
    }

    void _reportViewer_Load(object sender, EventArgs e)
    {
        if (!_isReportViewerLoaded)
        {
            Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();
            BossbergDataset dataset = DataAccessConstants.myDataset;

            dataset.BeginInit();

            reportDataSource1.Name = "DataSet1"; //Name of the report dataset in our .RDLC file
            reportDataSource1.Value = dataset.Table1;
            this._reportViewer.LocalReport.DataSources.Add(reportDataSource1);
         //My testReport.Rdlc has the [Copy to Output Directory] set to [Copy Always]
            this._reportViewer.LocalReport.ReportPath = @"Reports/TestReport.rdlc";

            dataset.EndInit();

            DataAccessConstants.Table1Adapter.Fill(dataset.Table1);

            _reportViewer.RefreshReport();

            _isReportViewerLoaded = true;
        }
    }
}

With my XAML being 我的XAML就是

<Page x:Class="MyProject.Views.ReportViewer"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
       xm![enter image description here][2]lns:rv="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms" 
      mc:Ignorable="d" 
      d:DesignHeight="300" d:DesignWidth="300"
    Title="ReportViewer">

    <Grid>
        <WindowsFormsHost>
            <rv:ReportViewer x:Name="_reportViewer"/>
        </WindowsFormsHost>
    </Grid>
</Page>

Also: 也:

  • Make sure you are copying your report files to your output directory. 确保将报告文件复制到输出目录。 If you are using syntax like ../../Myreport.rdlc you are probably not copying to the output directory. 如果您使用的语法如../../Myreport.rdlc ,则可能无法复制到输出目录。 输出目录要求

  • Make sure you are referencing the right version of the ReportViewer dll. 确保您引用了正确版本的ReportViewer DLL。 When I went to References > Add Reference... > Assemblies > Extensions and found the report viewer dll it was an old version. 当我转到References> Add Reference ...> Assemblies> Extensions并找到报表查看器dll时它是旧版本。 I needed to explicitly navigate to 我需要明确导航到

    C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\ReportViewer\\Microsoft.ReportViewer.WinForms.dll

    To find the latest. 要找到最新的。 If you get it wrong you'll get an error like 如果你弄错了,你会得到一个错误

    The report definition is not valid. 报告定义无效。 Details: The report definition has an invalid target namespace ' http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition ' which cannot be upgraded. 详细信息:报表定义具有无效的目标命名空间“ http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition ”,无法升级。

Where do you associate localReport with your reportViewer? 在哪里将localReport与reportViewer相关联? Instead of: 代替:

  using (StreamReader rdlcSR = new StreamReader(@"Resources\VisibleAssets.rdlc"))
  {
      localReport.LoadReportDefinition(rdlcSR);

      localReport.Refresh();
  }

I used: 我用了:

  using (StreamReader rdlcSR = new StreamReader(@"Resources\VisibleAssets.rdlc"))
  {
      reportViewer1.LocalReport.LoadReportDefinition(rdlcSR);

      reportViewer1.LocalReport.Refresh();
  }

And it seems to be working for me. 它似乎对我有用。

Exactly like what you said because that rdlc requires some sort of a dataSource :) It is a tricky issue in Report viewer and to solve it I wrote a method that will bind the report direct from Datatable: 完全像你说的那样,因为rdlc需要某种dataSource :)这是一个棘手的问题在报表查看器中并解决它我编写了一个方法,将直接从Datatable绑定报表:

private void GenerateReportDirect(ReportViewer reportViewer, string datasource, DataTable dt, string reportpath)
{
    reportViewer.LocalReport.ReportPath = reportpath;
    ReportDataSource repds = new ReportDataSource(datasource, dt);
    reportViewer.LocalReport.DataSources.Clear();
    reportViewer.LocalReport.DataSources.Add(repds);
    reportViewer.LocalReport.Refresh();
}

and to implement this method you have to specify putting the string of dataset table adapter just a name but our report will take the data to bind from the data table (we will cheat on our report viewer :) ) 要实现此方法,您必须指定将数据集表适配器的字符串作为名称,但我们的报告将从数据表中绑定数据(我们将在报表查看器上作弊:))

private void BindReport(DataTable dt)
    {
            string reportPath = Server.MapPath("StudentBus.rdlc");
            GenerateReportDirect(ReportViewer1, "StudentDataSet_usp_RPT_StudentBus", dt, reportPath);
    }

I hope this will help :) . 我希望这个能帮上忙 :) 。

I had this same issue occur with one of my reports. 我的一个报告发生了同样的问题。 It was a local, embedded report. 这是一份本地的嵌入式报告。

  1. I didn't have the ReportEmbeddedResource property set. 我没有设置ReportEmbeddedResource属性。
  2. When I did set ReportEmbeddedResource property , it still gave the error because the report name had incorrect case - myApp.reports.rptMyJobstatus.rdlc instead of myApp.reports.rptMyJobStatus.rdlc . 当我设置了ReportEmbeddedResource property ,它仍然给出了错误,因为报告名称的大小写错误 - myApp.reports.rptMyJobstatus.rdlc而不是myApp.reports.rptMyJobStatus.rdlc

Therefore, you need to check both of these conditions. 因此,您需要检查这两个条件。

如果要在代码中设置ReportEmbeddedResource属性而不是报告路径,则从XYZ.rdlc文件的属性将Build Action属性更改为Embedded Resource将帮助您解决大部分问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM