SSRS使用ADO报告跨不同环境的部署



我能够部署ssrs报告。使用azure扩展成功地将RDL文件传输到目标服务器。但是现在,如果我必须将它们部署到不同的环境中,比如preprod,prod。我需要手动更改.rdl文件中的连接字符串。我怎样才能使这个过程自动化呢?

在我们的环境中,我们为每个环境设置一个数据源,然后在创建/部署报告之后,我们将其数据源设置为该环境的DataSource(注意,这是使用遗留的SOAP API,如果使用REST API,则需要更改此示例):

param(
[string]$environment = "",
[string]$reportServerUri = "https://localhost:443/SSRS"
)
$rs = New-WebServiceProxy -Uri $reportServerUri -UseDefaultCredential
$targetFolderPath = ("/ChangeThisRootFolderToWhereverYouWantItToBe/Reports/{0}" -f $environment)
$newDataSourcePath = ("/ChangeThisRootFolderToWhereverYouWantItToBe/DataSources/{0}/ChangeThisDataSource" -f $environment)
$newDataSourceName = "ChangeThisDataSource"
$warnings = $null
Get-ChildItem *.rdl | Foreach-Object {
$reportName = [System.IO.Path]::GetFileNameWithoutExtension($_.Name)
$bytes = [System.IO.File]::ReadAllBytes($_.FullName)

Write-Output "Uploading report ""$reportName"" to ""$targetFolderPath""...`r`n"
$warnings = $rs.CreateReport(
$reportName,      # Report name
$targetFolderPath,# Destination folder
$true,            # Overwrite report if it exists?
$bytes,           # .rdl file contents
$null)            # Properties to set.
$warnings | ForEach-Object {
Write-Output ("Warning: {0}" -f $_.Message)
}
$reportPath = "$($targetFolderPath)/$($reportName)"
$dataSources = $rs.GetItemDataSources($reportPath) 
$dataSources | ForEach-Object { 
$proxyNamespace = $_.GetType().Namespace 
$myDataSource = New-Object ("$proxyNamespace.DataSource") 
$myDataSource.Name = $newDataSourceName 
$myDataSource.Item = New-Object ("$proxyNamespace.DataSourceReference") 
$myDataSource.Item.Reference = $newDataSourcePath 
$_.item = $myDataSource.Item 
$rs.SetItemDataSources($reportPath, $_) 
Write-Output "Changing report's DataSource reference ($($_.Name)) to: $($_.Item.Reference)"; 
} 
Write-Output "" 
}

相关内容

  • 没有找到相关文章

最新更新