[英]How to set correct DataSource in PowerShell for SSRS reports
I have a PowerShell script that should set the correct data source for a report. 我有一个PowerShell脚本,应该为报表设置正确的数据源。
I have more data sources for example DS1 and DS2. 我有更多的数据源,例如DS1和DS2。
Here is part of my PowerShell code: 这是我的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,$_ ) }
The problem is probably in SetItemDataSources
where I have $datasources.$DataSourceFolder
问题可能
SetItemDataSources
在我有$datasources.$DataSourceFolder
SetItemDataSources
中
If someone knows how I can fix this I will be happy. 如果有人知道我该如何解决,我会很高兴。
I am using primarily SSRS 2008 but I am sure your issue is that the overload for SetItemDataSources
is looking for a DataSource object . 我主要使用SSRS 2008,但是我确定您的问题是
SetItemDataSources
的重载正在寻找DataSource对象 。 Not just a path to the 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)
Notes about the above code: 有关上述代码的注意事项:
$ssrsServiceNamespace.DataSource
comes from the connection object. $ssrsServiceNamespace.DataSource
来自连接对象。 It creates an instance specific DataSource object. 它创建一个实例特定的DataSource对象。 For me, making a generic one ended up with type conversion errors causing
SetItemDataSources()
to fail. 对我来说,制作一个通用类最终会导致类型转换错误,从而导致
SetItemDataSources()
失败。 $ReportService.Gettype().Namespace
. $ReportService.Gettype().Namespace
。 So for me that works out to Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1tServer_ReportService2005_asmx
and my way look nicer and theoretically helps my code be more portable between SSRS environments. 因此,对我来说,它适用于
Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1tServer_ReportService2005_asmx
而且我的方法看起来更好,并且理论上可以帮助我的代码在SSRS环境之间更易于移植。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.