简体   繁体   中英

SSRS Report Viewer doesn't detect datasource?

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.

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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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