C# rdlc Cannot create a DataReader for dataset “ProjectDS_ObservationImages”

crdlcreporting-servicesreportviewer

I have the following issue appearing in a report, the data for which is dynamically loaded using C# in a win-forms .net 4 application.

Cannot create a DataReader for dataset "projectDS_ObservationImages"

The source that loads the report with data :

this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("ProjectDS_Site", this._dsProjectData.Tables["Site"]));
this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("ProjectDS_Client", this._dsProjectData.Tables["Client"]));
this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("ProjectDS_Head", this.getRangedHeadersCopy(this._htExcludeHeaders)));
this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("ProjectDS_Obs", this.getRangedObservationsCopy(this._htExcludeObservations)));
this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("ProjectDS_Images", dtProjectImages));
this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("ProjectDS_PMPL", this._dtPerMeterPerLineHeaders));
this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("ProjectDS_ObservationImages", this._dtObervsationImages));

It is the last DataSource being added to the report that causes the issue.

Each DataSource is in fact a DataTable. All are members of a DataSet in this project (or have cloned a schema), which is used as the only DataSet in the report. The names of the passed DataTables and the names of the Data Sets within the report, match 100%.

All other data passed to the report work, there is nothing special about this data source as opposed to the other 6 successfully passed.

No errors are provided in output when the report is processed.

What could cause the DataReader to fail?

Thanks for any input.

UPDATE ————————————————————————

Renaming does not work, rebuilding the DataTable by hand does not work, Creating and including a new DataTable with the same data does not work.

Copy and pasting the report elements into a sub report, and including the sub report on the main report, everything works fine, same data building code, same data, and same report layout.

Could the rdlc file be corrupt?

Best Answer

I had to look into this in more detail, I still don't understand why but I do have a way to solve the issue that does not require a sub-report, and may help others.

Open the report in source mode : right click in the solution explorer, open with, and then XML editor.

In the rdlc source, you will see an element <DataSets> which is the parent to your report defined Data Sets, each represented as a <DataSet> node.

In my case the one the causes the cannot create Data Reader error is last.

Cannot create a Data Reader for dataset "projectDS_ObservationImages"

<DataSets>
    <DataSet Name="ProjectDS_Head">
      <Query>
        <DataSourceName>ProjectDS</DataSourceName>
        <CommandText>/* Local Query */</CommandText>
      </Query>
      <Fields>
       ...
      </Fields>
      <rd:DataSetInfo>
        <rd:DataSetName>ProjectDS</rd:DataSetName>
        <rd:SchemaPath>C:\...\ProjectDS.xsd</rd:SchemaPath>
        <rd:TableName>Headers</rd:TableName>
        <rd:TableAdapterFillMethod>Fill</rd:TableAdapterFillMethod>
        <rd:TableAdapterGetDataMethod>GetData</rd:TableAdapterGetDataMethod>
        <rd:TableAdapterName>HeadersTableAdapter</rd:TableAdapterName>
      </rd:DataSetInfo>
    </DataSet>
    <DataSet Name="ProjectDS_Obs">
      <Query>
        <DataSourceName>ProjectDS</DataSourceName>
        <CommandText>/* Local Query */</CommandText>
      </Query>
      <Fields>
        ...
      </Fields>
      <rd:DataSetInfo>
        <rd:DataSetName>ProjectDS</rd:DataSetName>
        <rd:SchemaPath>C:\...\ProjectDS.xsd</rd:SchemaPath>
        <rd:TableName>Observations</rd:TableName>
        <rd:TableAdapterFillMethod>Fill</rd:TableAdapterFillMethod>
        <rd:TableAdapterGetDataMethod>GetData</rd:TableAdapterGetDataMethod>
        <rd:TableAdapterName>ObservationsTableAdapter</rd:TableAdapterName>
      </rd:DataSetInfo>
    </DataSet>
    <DataSet Name="ProjectDS_Client">
      <Query>
        <DataSourceName>ProjectDS</DataSourceName>
        <CommandText>/* Local Query */</CommandText>
      </Query>
      <Fields>
        ...
      </Fields>
      <rd:DataSetInfo>
        <rd:DataSetName>ProjectDS</rd:DataSetName>
        <rd:SchemaPath>C:\...\ProjectDS.xsd</rd:SchemaPath>
        <rd:TableName>Client</rd:TableName>
        <rd:TableAdapterFillMethod>Fill</rd:TableAdapterFillMethod>
        <rd:TableAdapterGetDataMethod>GetData</rd:TableAdapterGetDataMethod>
        <rd:TableAdapterName>ClientTableAdapter</rd:TableAdapterName>
      </rd:DataSetInfo>
    </DataSet>
    <DataSet Name="ProjectDS_Site">
      <Query>
        <DataSourceName>ProjectDS</DataSourceName>
        <CommandText>/* Local Query */</CommandText>
      </Query>
      <Fields>
        ...
      </Fields>
      <rd:DataSetInfo>
        <rd:DataSetName>ProjectDS</rd:DataSetName>
        <rd:SchemaPath>C:\...\ProjectDS.xsd</rd:SchemaPath>
        <rd:TableName>Site</rd:TableName>
        <rd:TableAdapterFillMethod>Fill</rd:TableAdapterFillMethod>
        <rd:TableAdapterGetDataMethod>GetData</rd:TableAdapterGetDataMethod>
        <rd:TableAdapterName>SiteTableAdapter</rd:TableAdapterName>
      </rd:DataSetInfo>
    </DataSet>
    <DataSet Name="ProjectDS_Images">
      <Query>
        <DataSourceName>ProjectDS</DataSourceName>
        <CommandText>/* Local Query */</CommandText>
      </Query>
      <Fields>
        ...
      </Fields>
      <rd:DataSetInfo>
        <rd:DataSetName>ProjectDS</rd:DataSetName>
        <rd:SchemaPath>C:\...\ProjectDS.xsd</rd:SchemaPath>
        <rd:TableName>ProjectImages</rd:TableName>
        <rd:TableAdapterFillMethod />
        <rd:TableAdapterGetDataMethod />
        <rd:TableAdapterName />
      </rd:DataSetInfo>
    </DataSet>
    <DataSet Name="ProjectDS_PMPL">
      <Query>
        <DataSourceName>ProjectDS</DataSourceName>
        <CommandText>/* Local Query */</CommandText>
      </Query>
      <Fields>
        ...
      </Fields>
      <rd:DataSetInfo>
        <rd:DataSetName>ProjectDS</rd:DataSetName>
        <rd:SchemaPath>C:\...\ProjectDS.xsd</rd:SchemaPath>
        <rd:TableName>PerMeterPerLine</rd:TableName>
        <rd:TableAdapterFillMethod />
        <rd:TableAdapterGetDataMethod />
        <rd:TableAdapterName />
      </rd:DataSetInfo>
    </DataSet>
    <DataSet Name="ProjectDS_ObservationImages">
      <Query>
        <DataSourceName>ProjectDS</DataSourceName>
        <CommandText>/* Local Query */</CommandText>
      </Query>
      <Fields>
       ...
      </Fields>
      <rd:DataSetInfo>
        <rd:DataSetName>ProjectDS</rd:DataSetName>
        <rd:SchemaPath>C:\...\ProjectDS.xsd</rd:SchemaPath>
        <rd:TableName>ObservationImagesEx</rd:TableName>
        <rd:TableAdapterFillMethod />
        <rd:TableAdapterGetDataMethod />
        <rd:TableAdapterName />
      </rd:DataSetInfo>
    </DataSet>
  </DataSets>

The fix was simply to cut and paste the problem <DataSet> node, to the front of the DataSets collection, so that it appears directly after the <DataSets> node.

  <DataSets>
     <DataSet Name="ProjectDS_ObservationImages">
     ...

Now the report works fine, with no error, and all data is loaded.

Why? I will leave this question open in the hope that someone can explain.

Related Topic