【问题标题】:How to set correct DataSource in PowerShell for SSRS reports如何在 PowerShell 中为 SSRS 报告设置正确的数据源
【发布时间】:2018-12-05 13:41:40
【问题描述】:

我有一个 PowerShell 脚本,它应该为报告设置正确的数据源。
我有更多数据源,例如 DS1 和 DS2。

这是我的 PowerShell 代码的一部分:

function UpgradeReport
{
    param
    (
        [string]$t,
        [string]$ReportFolder,
        [string]$ReportName,
        [string]$DataSourceFolder,
        [string]$IssueId
    )

if([string]::IsNullOrEmpty($DataSourceFolder)) { $DataSourceFolder="DS1" }

.......
# if all ok since now, report is uploaded
        # set datasource if new report
        if (!$reports.$reportName) {
            Write-Host $reportName ' is new. Setting data source: ' $DataSourceFolder
            $Proxy.SetItemDataSources("/$reportFolder/$reportName", $datasources.$DataSourceFolder)
        }
        Write-Output "$(Timestamp) Finished InstallReports for $ReportName"

.....

# get list of all datasources
$Proxy.ListChildren('/Data Sources', $false) | ForEach-Object { $datasources.add($_.Name,$_ ) }

问题可能出在SetItemDataSources 我有$datasources.$DataSourceFolder

如果有人知道我该如何解决这个问题,我会很高兴。

【问题讨论】:

  • $datasources 是一个未知变量。至少,在您向我们展示的内容中,它“就在那里”。我认为您可能需要将$Proxy.SetItemDataSources("/$reportFolder/$reportName", $datasources.$DataSourceFolder) 更改为$Proxy.SetItemDataSources("/$reportFolder/$reportName", $DataSourceFolder)
  • 修复什么?有什么问题?我们需要对问题的描述以及任何错误消息。

标签: powershell reporting-services reporting-services-2012


【解决方案1】:

我主要使用 SSRS 2008,但我确定您的问题是 overload for SetItemDataSources is looking for a DataSource object。不仅仅是对象的路径。

$newDataSource = New-Object "$ssrsServiceNamespace.DataSource"
$newDataSource.Name = $DataSourceName
$newDataSource.Item = New-Object ("$ssrsServiceNamespace.DataSourceReference")
$newDataSource.Item.Reference = $DataSourcePath
Write-Verbose "New Datasource Name     : $($newDataSource.Name)"
Write-Verbose "New Datasource Reference: $($newDataSource.Reference)"

$ReportService.SetItemDataSources($reportPath, $newDataSource)

以上代码注意事项:

$ssrsServiceNamespace.DataSource 来自连接对象。它创建一个实例特定的 DataSource 对象。对我来说,制作一个通用的最终会导致类型转换错误导致SetItemDataSources() 失败。 $ReportService.Gettype().Namespace。所以对我来说,这适用于Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1tServer_ReportService2005_asmx,而且我的方式看起来更好,理论上可以帮助我的代码在 SSRS 环境之间更便携。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多