SSRS RDL Mapping datasources programmatically

后端 未结 1 1902
我在风中等你
我在风中等你 2021-01-15 03:12

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

相关标签:
1条回答
  • 2021-01-15 03:30

    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.

    0 讨论(0)
提交回复
热议问题