Home » Visual Studio

Subreports and datasources

Hi, our current solution grabs a reports definition, modifies it to handle collapsable columns, modifies the reports datasource (else it blows up), then sends it back to the server for processing.  These modifications are done by doing string replaces. This has worked fine until now.  

The business has created reports with sub-reports.  The main report runs fine but where the sub-reports are to be displayed we get an error.  I've searched the net and the fix has been stated that when using web service calls to execute a report you need to use absolute datasource references vs relative.  This makes sense as that's why i modify the reports datasource above manually.  

Question 1:  Do i also need to load each sub-report, manually modify the definition to use absolute datasource references then send back to the server?  Is this best practice?

Question 2: Am i doing this all wrong?  Is there a better way of modifying a reports datasource than performing a string replace on the rdl file?

I'm thinking i've going about this the wrong way and hoping someone can "show me the light!"

Thanks for any help in advance!





4 Answers Found


Answer 1

Hi John,

SubReport has its own datasource. If the field that is the subreport's parameter associated is not changed, we don't need to modify  the subreport's datasource  referenece.
However, if the associated fields are changed, we need to modify the subreport's definition  even datasource reference.

If we just want to change the datasource reference, we can use the SetItemDataSources method to modify it.
Below is the sample code for your reference:

Dim reference AsNew DataSourceReference()
 reference.Reference = calalogItem.Path
 Dim source AsNew DataSource()
 source.Item = reference 
 source.Name = calalogItem.Name
 Dim sources As DataSource() = New DataSource(0) {}
 sources(0) = source
 rs.SetItemDataSources("report path", sources)

Anyway, in order to modify other elements, "string replace" is the right way.

If there is anything unclear, please feel free to ask.

Jin Chen


Answer 2

Thanks Jin, i'll give your code above a try.

Please do me a favor and confirm my overall understanding of datasources  when the report  is called using LoadReportDefinition followed by Render:

Our data source name for all reports  is called : reports.rds.  All of our reports (including sub-reports) reference that name.  We deploy that datasource  to a directory on the server  called DataSources/reports.rds.  All of our reports live on the server at Reports/<report name>.

- when i run a report I must modify  the reports datasource prior to calling Render as you've instructed above, so that the modified report points to an absolute  reference vs. a relative  path else the report will fail.  Meaning i have to change the reports datasource from reports.rds to DataSources/reports.rds.

- If the above report contains any sub-reports, i must also modify each sub-reports  datasource using the above code as well else each sub-report  will fail.

Are my statements true?

Thanks again for your help.  Have a great weekend.






Answer 3

I'm starting to pull my hair out on this one.   when i run the code below it errors out on the "SetItemDataSources" call.  

"The data source 'reportdatasource' cannot be found"


If i comment out the code below and simply do a string  replace it works:

strProductionReport.Replace("<DataSourceReference>" & Me.ReportDataSourceName & "</DataSourceReference>", "<DataSourceReference>" & Me.ReportDataSourcePath & "</DataSourceReference>")


Thoughts?  Doing a string replace  is not the way to do it.. and again.. i'll have to do it for every sub-report  as well.

Thanks, John


    Dim reportDataSources() As datasource  = _rsService.GetItemDataSources(Me.ReportUrl)
    If Not (reportDataSources Is Nothing) Then
      For Each ds As DataSource In reportDataSources
        Dim reference As New DataSourceReference
        reference.Reference = Me.ReportDataSourcePath
        Dim dss As New DataSource
        dss.Item = CType(reference, DataSourceReference)
        dss.Name = Me.ReportDataSourceName
        Dim dsList(0) As DataSource
        dsList(0) = dss
        dsList(0).Name = Me.ReportDataSourceName
        _rsService.SetItemDataSources(Me.ReportUrl, dsList)
      Next ds
    End If


Answer 4


if anyone has any ideas as to why the above code doesnt work please let me know.  Thanks!  john





<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure