Learner
Learner

Reputation: 351

SSRS SetItemDataSource giving exception

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)"

#

Upvotes: 1

Views: 1787

Answers (1)

Developer
Developer

Reputation: 8646

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

Upvotes: 0

Related Questions