SSRS Report Viewer doesn't detect datasource?

走远了吗. 提交于 2019-12-12 04:46:41

问题


I built a very simple report (.rdl) in ReportBuilder 3.0. 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. I save and close. Then I try to open and view the report in VS 2010 via MicroSoft.Reporting.WebForms.ReportViewer. I can load a completely blank RDL file (text only) in my c#/ASP.NET website locally.

            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'.

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.

<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:

            //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? 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.


回答1:


In local processing mode datasets must be provided by calling code, i.e. 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 )



来源:https://stackoverflow.com/questions/12788313/ssrs-report-viewer-doesnt-detect-datasource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!