none
Report not finding Data Source at run time RRS feed

  • Question

  • This is the first time I've created an rdlc report.  I've got it all laid out, but am having trouble setting up the Data Source.  I need to pull in a set of data from a Service using the ClientProxy.

    I've copied the way a similar report was already set up in the application.  That report uses a data source from the same Client Proxy class and works fine.  I have noticed that when I look at the Data Source associated with that report, under the Assembly details it has a PublicKeyToken.  Mine says PublicKeyToken=null.

    I set up the new Data Source using the Add New Data Source wizard.  I selected Object and navigated to the right object in the right ClientProxy class.  It seemed to create the Data Source ok, and I was able to select it to assign to my report.  However, as I say, the PublicKeyToken is null, and when I run the report, I get the message "A data source instance has not been supplied for the data source".

    I don't think it can be down to the code which is actually calling the report viewer as I've copied that from the way the other report works and don't think I've missed anything.

    Can anyone help?

    • Moved by Barry Wang Monday, December 16, 2013 6:40 AM RDLC
    Friday, December 13, 2013 12:56 PM

Answers

  • Reports do not have a data source at run time until you add one. That is why you cannot get the name of the DataSources[0]. There is no datasources[0] yet. DataSources[0] is null. What is the Name property of null? 

    The design time data source of the report is just a mapping. If you look at the xml of the rdlc then you will see the mappings. It does not mean that at runtime the report will have a data source by that name. You must set it as you have done in that second line of code.

    After you run that second line of code, then you could access DataSources[0] because now it has one.



    Bob - www.crowcoder.com

    • Marked as answer by Karen Wickham Thursday, January 2, 2014 8:32 AM
    Tuesday, December 31, 2013 4:28 PM

All replies

  • I would guess that the dataset your report is built with has a different name than the reportdatasource you are assigning to the viewer's report.

    ReportDataSource mainRDS = new ReportDataSource("YourDataSet", someList); //"YourDataSet" has to be the exact same name as the dataset from the report designer
                this.reportViewer1.LocalReport.DataSources.Clear();
                this.reportViewer1.LocalReport.DataSources.Add(mainRDS);


    Bob - www.crowcoder.com

    Friday, December 13, 2013 1:09 PM
  • Hi,

    The code is using the LocalReport setting in the Report Viewer, and that is returning 0 Data Sources.


    ReportDataSource myRDS = new ReportDataSource(this.rvSubCustodianReport.LocalReport.DataSources[0].Name, myReportResults);

    Friday, December 13, 2013 3:26 PM
  • Hi,

    The code is using the LocalReport setting in the Report Viewer, and that is returning 0 Data Sources.


    ReportDataSource myRDS = new ReportDataSource(this.rvSubCustodianReport.LocalReport.DataSources[0].Name, myReportResults);

    The local report will have no data sources until you add them. Review my code above.

    Your code doesn't make sense. You're trying to get a reportdatasource from the report that doesn't have one yet so that you can assign it to the report. ???


    Bob - www.crowcoder.com

    Friday, December 13, 2013 3:36 PM
  • And yet this is the way the other report that I've copied from does it.

    The LocalReport property on the report viewere has a sub property of ReportEmbeddedResource, which is set to the name of the rdlc report (again this is the way the other report does it).

    The rdlc report has a DataSource assigned to it.  The only difference I can see between the way the two reports work is that the one which does work has a DataSource assigned to it which has a PublicKeyToken, whereas the PublicKeyToken on the one which doesn't work is null.  But I don't know how to set that up correctly.

    The report which works has a data source which looks like this:-

    <?xml version="1.0" encoding="utf-8"?>
    <!--
        This file is automatically generated by Visual Studio .Net. It is 
        used to store generic object data source configuration information.  
        Renaming the file extension or editing the content of this file may   
        cause the file to be unrecognizable by the program.
    -->
    <GenericObjectDataSource DisplayName="SLPositionRequestReports" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
       <TypeInfo>NT.Slims.Svc.WCF.ClientProxy.ReportsMgmtProxy.SLPositionRequestReports, NT.Slims.Svc.WCF.ClientProxy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6fec74aa72e4a0dd</TypeInfo>
    </GenericObjectDataSource>

    The one which doesn't looks like this:-

    <?xml version="1.0" encoding="utf-8"?>
    <!--
        This file is automatically generated by Visual Studio .Net. It is 
        used to store generic object data source configuration information.  
        Renaming the file extension or editing the content of this file may   
        cause the file to be unrecognizable by the program.
    -->
    <GenericObjectDataSource DisplayName="AIFMDReportingReports" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
       <TypeInfo>NT.Slims.Svc.WCF.ClientProxy.ReportsMgmtProxy.AIFMDReportingReports, NT.Slims.Svc.WCF.ClientProxy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
    </GenericObjectDataSource>

    Friday, December 13, 2013 3:47 PM
  • The public key token just means that the assembly was digitally signed. Your other service may not be signed, that should not be an issue.

    Try just calling the service and see what it returns. Make sure that is returning the collection you expect it to. Then we can work on adding it as a ReportDataSource.


    Bob - www.crowcoder.com

    Friday, December 13, 2013 3:53 PM
  • Thanks for spending time on this.  I'm about to leave the office for the day.  Will look at this again on Monday.  Have a great weekend.
    Friday, December 13, 2013 4:01 PM
  • Hi,

    I've managed to get the report to work, but only by hard coding the name of the data source.

    When I bring up the rdlc in Visual Studio and go into Report>Data Sources in the menu, there is one data source listed for this report - called NT_Slims_Svc_WCF_ClientProxy_ReportsMgmtProxy_AIFMDReportingReports.

    The code below works, but only because I've replaced the commented line with the line containing the hardcoded name of the data source.  When I debug through it using the commented out line, the property this.rvSubCustodianReport.LocalReport.DataSources has a count of 0.  So it can't find the data source name.  rvSubCustodianReport is a ReportViewer component.

    //ReportDataSource myRDS = new ReportDataSource(this.rvSubCustodianReport.LocalReport.DataSources[0].Name, myReportResults);
    ReportDataSource myRDS = new ReportDataSource("NT_Slims_Svc_WCF_ClientProxy_ReportsMgmtProxy_AIFMDReportingReports", myReportResults);

    Tuesday, December 31, 2013 4:14 PM
  • Reports do not have a data source at run time until you add one. That is why you cannot get the name of the DataSources[0]. There is no datasources[0] yet. DataSources[0] is null. What is the Name property of null? 

    The design time data source of the report is just a mapping. If you look at the xml of the rdlc then you will see the mappings. It does not mean that at runtime the report will have a data source by that name. You must set it as you have done in that second line of code.

    After you run that second line of code, then you could access DataSources[0] because now it has one.



    Bob - www.crowcoder.com

    • Marked as answer by Karen Wickham Thursday, January 2, 2014 8:32 AM
    Tuesday, December 31, 2013 4:28 PM
  • Ah that makes sense.  Thank you.
    Thursday, January 2, 2014 8:32 AM