简体   繁体   English

SSRS Report Viewer不检测数据源?

[英]SSRS Report Viewer doesn't detect datasource?

I built a very simple report (.rdl) in ReportBuilder 3.0. 我在ReportBuilder 3.0中构建了一个非常简单的报告(.rdl)。 It has a connection to my database, and gets city out of the address field. 它与我的数据库有连接,并从地址字段中获取城市。

SELECT TOP 10 City, COUNT(City) FROM [MYDB].[dbo].[ResidentialAddress] WHERE StateName = 'WA' OR StateName = 'Washington' GROUP BY City ORDER BY COUNT(City) DESC

This works in ReportBuilder. 这适用于ReportBuilder。 I save and close. 我保存并关闭。 Then I try to open and view the report in VS 2010 via MicroSoft.Reporting.WebForms.ReportViewer. 然后我尝试通过MicroSoft.Reporting.WebForms.ReportViewer在VS 2010中打开并查看报告。 I can load a completely blank RDL file (text only) in my c#/ASP.NET website locally. 我可以在我的c#/ ASP.NET网站本地加载一个完全空白的RDL文件(仅文本)。

            this.MyReportViewer.Reset();
            this.MyReportViewer.ProcessingMode = ProcessingMode.Local;
            this.MyReportViewer.AsyncRendering = false;
            this.MyReportViewer.LocalReport.LoadReportDefinition(new StreamReader("H:\\DataReportsViewer\\DataReportsViewer\\" + RDLFileList.SelectedValue));
            this.MyReportViewer.LocalReport.ReportPath = RDLFileList.SelectedValue;          
            this.MyReportViewer.ShowReportBody = true;
            this.MyReportViewer.LocalReport.Refresh();

However, as soon as I add a chart, I get this error: 但是,只要我添加图表,我就会收到此错误:

A data source instance has not been supplied for the data source 'DataSet1'. 尚未为数据源“DataSet1”提供数据源实例。

It doesn't make sense to me, because when I open up the RDL file, the connection string and query are there, seemingly as they should be. 这对我来说没有意义,因为当我打开RDL文件时,连接字符串和查询就在那里,看起来应该是这样。

<DataSources>
    <DataSource Name="DataSource1">
      <ConnectionProperties>
        <DataProvider>SQL</DataProvider>
        <ConnectString>Data Source=MYSERVER;Initial Catalog=Ad_Dev</ConnectString>
        <IntegratedSecurity>true</IntegratedSecurity>
      </ConnectionProperties>
      <rd:SecurityType>Integrated</rd:SecurityType>
      <rd:DataSourceID>350f6976-9402-43fd-b8f8-8f809f116f84</rd:DataSourceID>
    </DataSource>
  </DataSources>
  <DataSets>
    <DataSet Name="DataSet1">
      <Query>
        <DataSourceName>DataSource1</DataSourceName>
        <CommandText>SELECT TOP 10 ResidentialAddress.City,COUNT(ResidentialAddress.City)
FROM ResidentialAddress
WHERE StateName = 'WA'
GROUP BY ResidentialAddress.City
ORDER BY COUNT(ResidentialAddress.City)</CommandText>
        <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
      </Query>
      <Fields>
        <Field Name="City">
          <DataField>City</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="ID">
          <DataField />
          <rd:TypeName>System.Int32</rd:TypeName>
        </Field>
      </Fields>
    </DataSet>
  </DataSets>

So, I attempted the workaround in my c# code: 所以,我在我的c#代码中尝试了解决方法:

            //Added line: TestDataSource runs same query and returns correctly loaded DataTable
            ReportDataSource reportDataSource = new ReportDataSource("DataSet1", TestDataSource()); 
            this.MyReportViewer.LocalReport.DataSources.Add(reportDataSource);

And that runs, but no data shows up. 而且运行,但没有数据出现。 I can't win! 我不能赢! :( :(

Any ideas? 有任何想法吗? Are SSRS and ASP.NET just not meant to play with each other? SSRS和ASP.NET是不是意味着互相玩耍? I was hoping to make a local test version of this report viewer, but I've already had to make a lot of hacks to even get the blank report to run locally. 我本来希望制作一个本报告查看器的本地测试版本,但我已经不得不做很多黑客甚至让空白报告在本地运行。

In local processing mode datasets must be provided by calling code, ie host program must execute all queries and pass that data to the report viewer. 在本地处理模式中,必须通过调用代码来提供数据集,即主机程序必须执行所有查询并将该数据传递给报表查看器。 Here is the example http://www.gotreportviewer.com/definedata/index.html On plus side, any data can be passed into the report viewer ( http://www.gotreportviewer.com/objectdatasources/index.html ) 以下是http://www.gotreportviewer.com/definedata/index.html上的示例另外,任何数据都可以传递到报告查看器( http://www.gotreportviewer.com/objectdatasources/index.html

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

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