SSRS SetItemDataSource giving exception

落爺英雄遲暮 提交于 2019-12-12 01:52:37

问题


Hello all I am trying to set the datasource to the created report but I am getting an exception as mentioned

This is the code I am using

$Proxy = New-WebServiceProxy -Uri $ReportingServiceUrl -UseDefaultCredential
$ReportName = "MyReport"
$path="/"
$allitems = $Proxy.ListChildren("/",$true)
#Select the newest report with correct name
$ThisReport = $allitems | where {($_.Name -eq $ReportName) } | Sort-Object ModifiedDate -Descending | Select -first 1
$datasource = $DataSourceName
$objdataSource = $Proxy.GetItemDataSources($thisreport.path)

#Generate new data source reference
$proxyNamespace = $objdataSource.GetType().Namespace
$DataSourceReference = new-object ("$proxynamespace.DataSourceReference")
$DataSourceReference.Reference = ($allitems | where {($_.Type -eq "DataSource") -and ($_.Name -eq $datasource)}).Path
$objdataSource[0].item = $DataSourceReference

Write-Verbose "Updating datasource"
$Proxy.SetItemDataSources($ThisReport.Path, $objdataSource)  //$ThisReport.Path I am getting this as /MyReport
# !!!! ERRORS HAVE BEEN ENCOUNTERED !!!! #

Exception calling "SetItemDataSources" with "2" argument(s): "System.Web.Services.Protocols.SoapException: The path of the item '' is not valid. The full path must be less than 260 characters long; other re strictions apply. If the report server is in native mode, the path must start with slash. ---> Microsoft.ReportingServices.Diagnostics.Utilities.InvalidItemPathException: The path of the item '' is not vali d. The full path must be less than 260 characters long; other restrictions apply. If the report server is in native mode, the path must start with slash. at Microsoft.ReportingServices.Library.ReportingService2005Impl.SetItemDataSources(String Item, DataSource[] DataSources, Guid batchId) at Microsoft.ReportingServices.Library.ReportingService2005Impl.SetItemDataSources(String Item, DataSource[] DataSources) at Microsoft.ReportingServices.WebServer.ReportingService2010.SetItemDataSources(String ItemPath, DataSource[] DataSources)"

#

回答1:


Here is what I figured out why it is throwing because of this line

$DataSourceReference.Reference = ($allitems | where {($_.Type -eq "DataSource") -and ($_.Name -eq $datasource)}).Path

This should be

$DataSourceReference.Reference = ($allitems | where {(**$_.TypeName** -eq "DataSource") -and ($_.Name -eq $datasource)}).Path

It is not able to set the DataSource path to the root (/) as it is returning null. Please try and let me know



来源:https://stackoverflow.com/questions/41824616/ssrs-setitemdatasource-giving-exception

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