Hi, I need to automate the deployment of our reports to the report server. I am using rs.exe and I have got it almost working as I need it to. The only part that I am stuck on is being able to change the report datasource once it has been uploaded to the
server.
An example;
My report locally refer to a datasource called 'Local_DS'.
'Local_DS' does not exist on my report server in the datasource folder BUT a datasource called 'LIVE_DS' does.
I need to change each reports datasource from 'Local_DS' to now use 'LIVE_DS'.
This is where I am stuck. I have gotten close, I think, but maybe looking at it too hard now and missing the obvious.
Here is what I have got so far;
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim item As CatalogItem
Dim items As CatalogItem()
Try
items = rs.ListChildren("/" + ReportFolder, False)
For Each item In items
Dim dataSources() As DataSource = rs.GetItemDataSources(item.Path)
For Each ds As DataSource In dataSources
'Set report DataSource references
Dim sharedDataSources(0) As DataSource
sharedDataSources(0) = GetDataSource(DataSourcePath, item.Name)
Dim sharedDataSourceReference0 As New DataSourceReference
sharedDataSourceReference0.Reference = DataSourcePath
Dim sharedDataSource0 As New DataSource
sharedDataSource0.Item = CType(sharedDataSourceReference0, DataSourceDefinitionOrReference)
sharedDataSource0.Name = DataSourceName
sharedDataSources(0) = sharedDataSource0
rs.SetItemDataSources("/Datasource/" + DataSourceName, sharedDataSources)
Console.WriteLine("Set " & ds.Name & " datasource for " & item.Path & " report")
Next
Next
Console.WriteLine("Shared data source reference set for reports in the {0} folder.", ReportFolder)
This does not seem to work for me. Can anyone point me to a working example?
Never mind, finally figured it out myself. I was under the mistaken beleif thqat you could change the name of the datasource as well as the path reference but it appears that you cannot change the name, just the path.
My working code;
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim item As CatalogItem
Dim items As CatalogItem()
Try
items = rs.ListChildren("/" + ReportFolder, False)
For Each item In items
Dim dataSources() As DataSource = rs.GetItemDataSources(item.Path)
For Each ds As DataSource In dataSources
'Set report DataSource references
Dim sharedDataSources(0) As DataSource
sharedDataSources(0) = GetDataSource(DataSourcePath, item.Name)
Dim sharedDataSourceReference0 As New DataSourceReference
sharedDataSourceReference0.Reference = DataSourcePath + "/" + DataSourceName
Dim sharedDataSource0 As New DataSource
sharedDataSource0.Item = CType(sharedDataSourceReference0, DataSourceDefinitionOrReference)
sharedDataSource0.Name = ds.Name
sharedDataSources(0) = sharedDataSource0
rs.SetItemDataSources(item.Path, sharedDataSources)
Console.WriteLine("Update '" & ds.Name & "' datasource for '" & item.Path & "' to datasource '" & DataSourcePath + "/" + DataSourceName & "'")
Next
Next
Console.WriteLine("Shared data source reference set for reports in the {0} folder.", ReportFolder)
Member
36 Points
254 Posts
RS.EXE - Automate report upload and change report datasource
Apr 27, 2017 10:37 AM|Scout7|LINK
Hi, I need to automate the deployment of our reports to the report server. I am using rs.exe and I have got it almost working as I need it to. The only part that I am stuck on is being able to change the report datasource once it has been uploaded to the server.
An example;
My report locally refer to a datasource called 'Local_DS'.
'Local_DS' does not exist on my report server in the datasource folder BUT a datasource called 'LIVE_DS' does.
I need to change each reports datasource from 'Local_DS' to now use 'LIVE_DS'.
This is where I am stuck. I have gotten close, I think, but maybe looking at it too hard now and missing the obvious.
Here is what I have got so far;
This does not seem to work for me. Can anyone point me to a working example?
Member
36 Points
254 Posts
Re: RS.EXE - Automate report upload and change report datasource
Apr 27, 2017 12:29 PM|Scout7|LINK
Never mind, finally figured it out myself. I was under the mistaken beleif thqat you could change the name of the datasource as well as the path reference but it appears that you cannot change the name, just the path.
My working code;