x
login about faq Site discussion (meta-askssc)

Change DataSource of SSRS Report with Powershell

Hi,

I'm trying to ahange data sources of multiple SSRS Report with Powershell to one shared data source on my reporting server. Here my code:

cls;
$reportserver = "myServer";

$url = "http://$($reportserver)/reportserver/reportservice2005.asmx?WSDL";
$ssrs = New-WebServiceProxy -uri $url -UseDefaultCredential -Namespace "ReportingWebService";

[ReportingWebService.DataSource[]] $myDataSource = new-object ReportingWebService.DataSource
$myDataSource[0].Name = "myDS" 
$myDataSource[0].Item = New-Object ReportingWebService.DataSourceReference 
$myDataSource[0].Item.Reference = "/Data Sources/MyDS" 

$reports = $ssrs.ListChildren('/DH', $false)

$reports | ForEach-Object {
 $reportPath = $_.path
 Write-Host "Report: " $reportPath
 $dataSources = $ssrs.GetItemDataSources($reportPath)
 $dataSources | ForEach-Object {
              Write-Host "Old source: $($_.Name), $($_.Item.ConnectString)"
              $ssrs.SetItemDataSources($reportPath, $myDataSource)
              Write-Host "New source: $($_.Name), $($_.Item.ConnectString)"
          }

 Write-Host "------------------------"
}

But I'm getting the following error when calling "SetItemDataSources"-method:

Argument "1" having the value "ReportingWebService.DataSource[]" of "SetItemDataSources" can not be converted to type "ReportingWebService.DataSource[]".

The question is: What's wrong? The types are the SAME!

Thanks!

more ▼

asked Feb 07 '12 at 01:42 PM in Default

eghetto gravatar image

eghetto
1.5k 6 13 17

(comments are locked)
10|1200 characters needed characters left

4 answers: sort voted first

I got it now! Here's the working solution:

cls;

 #Set variables:
 $reportserver = "myServer";
 $url = "http://$($reportserver)/reportserver/reportservice2005.asmx?WSDL";
 $newDataSourcePath = "/Data Sources/MyDS";
 $newDataSourceName = "MyDS";
 $reportFolderPath = "/DH";
 #------------------------------------------------------------------------

 $ssrs = New-WebServiceProxy -uri $url -UseDefaultCredential

 $reports = $ssrs.ListChildren($reportFolderPath, $false)

 $reports | ForEach-Object {
 $reportPath = $_.path
 Write-Host "Report: " $reportPath
 $dataSources = $ssrs.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

 $ssrs.SetItemDataSources($reportPath, $_)

 Write-Host "Report's DataSource Reference ($($_.Name)): $($_.Item.Reference)";
 }

 Write-Host "------------------------"
 }
more ▼

answered Feb 16 '12 at 10:31 AM

eghetto gravatar image

eghetto
1.5k 6 13 17

(comments are locked)
10|1200 characters needed characters left

Thanks, Worked like a charm.

One Small correction in the second one, need to update the $url

more ▼

answered Jan 09 at 05:16 PM

rajinxerox gravatar image

rajinxerox
0

(comments are locked)
10|1200 characters needed characters left

Declaring and Defining the $url variable is missing. Other than that, It works perfect

more ▼

answered Jan 09 at 05:17 PM

rajinxerox gravatar image

rajinxerox
0

(comments are locked)
10|1200 characters needed characters left

David Levy wrote a script that changes the credentials of SSRS reports using PowerShell that I think you might want to compare with yours on how he uses SetItemDataSources.

I think your line $myDataSource variable needs to be adjusted in how you are trying to set that up.

more ▼

answered Feb 07 '12 at 02:32 PM

Shawn_Melton gravatar image

Shawn_Melton
4.7k 13 17 27

Well, thanks. But I know the script by David Levy already. It doesn't help me. I want to change the reference inside the report from development to production SHARED datasource. David Lavy's script just changes credentials of an EMBEDED data source.

Anyway, my guess is: "[ReportingWebService.DataSource[]]" is Reporting Service 2000 class, not 2005... Maybe I'm wrong...

Feb 07 '12 at 02:38 PM eghetto

Debug confirmes that both variables are of the same type but DIFFERENT ASSEMBLIES! "nhdifv-s" vs. "lrc8sdta"

[DBG]: PS C: > $dataSources.GetType().Assembly.FullName --> nhdifv-s, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

[DBG]: PS C: > $myDataSource.GetType().Assembly.FullName --> lrc8sdta, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

[DBG]: PS C: > $dataSources.GetType().FullName --> ReportingWebService.DataSource[]

[DBG]: PS C: > $myDataSource.GetType().FullName --> ReportingWebService.DataSource[]

Feb 07 '12 at 02:52 PM eghetto
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x95
x20
x19
x3

asked: Feb 07 '12 at 01:42 PM

Seen: 2007 times

Last Updated: Feb 11 at 11:27 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.