SSRS RDL Mapping datasources programmatically

怎甘沉沦 提交于 2019-12-01 09:21:17

问题


We are using rs.exe for deployment of RDLs to ReportServer.

As DataSource, Shared DataSet and RDLs reside in different folders.After deploying RDLs, mapping between RDL to Shared DataSets and Shared DataSets to DataSource are removed.

I have to map each RDL manually to the respective DataSets and DataSource. I have 200 RDLs and it's really hard to do manually.

I need code for Mapping RDLs to Datasets after deploying the RDLs

Could some body help with some code for my requirement?


回答1:


I've created an rs.exe script that performs the following:

  1. Deploys a report based on a file Report.rdl. The report has one reference to a Shared Data Source and one reference to a Shared DataSet. The report is deployed to the report server / directory.

  2. Sets the Data Source for the report to an existing Shared Data Source on the report server. The Data Source is deployed as /Data Sources/DS.

  3. Set the DataSet for the report to an existing Shared DataSet on the report server. The Data Source is deployed as /Datasets/DataSet.

The script contains the following code:

Public Sub Main()
    Dim definition As [Byte]() = Nothing
    Dim warnings As Warning() = Nothing

    'Read report from file on disk
    Dim stream As FileStream = File.OpenRead("Report.rdl")
    definition = New [Byte](stream.Length - 1) {}
    stream.Read(definition, 0, CInt(stream.Length))
    stream.Close()

    'Deploy report
    'ItemType, name, folder, overwrite, definition, properties 
    rs.CreateCatalogItem("Report", "Report", "/", True, definition, Nothing, warnings)

    'Update existing report Data Souce reference to Shared Data Source on server
    Dim dataSourceRefs(0) As DataSource
    Dim dsr As New DataSourceReference
    dsr.Reference = "/Data Sources/DS"
    Dim ds As New DataSource
    ds.Item = CType(dsr, DataSourceDefinitionOrReference)
    ds.Name = "DS"
    dataSourceRefs(0) = ds

    rs.SetItemDataSources("/Report", dataSourceRefs)

    'Update existing report DataSet reference to Shared DataSet on server   
    Dim dataSetRefs(0) as ItemReference
    Dim dset as New ItemReference
    dset.Name = "DataSet"
    dset.Reference = "/Datasets/DataSet"
    dataSetRefs(0) = dset

    rs.SetItemReferences("/Report", dataSetRefs)

End Sub

It sounds like you're already deploying the reports succesfully.

So, the main things to note are the code snippets that update the Data Source reference and the DataSet reference. The methods to note are:

SetItemDataSources to update the Data Source.

SetItemReferences to update the DataSet.

This is for one report, so you'll need to wrap up the code in a sub routine for your deployment script, but hopefully this will help you out.



来源:https://stackoverflow.com/questions/16083951/ssrs-rdl-mapping-datasources-programmatically

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