Save the following code as MyRSScript.rss and run like this from the command prompt.
> rs -i MyRSScript.rss -s http://localhost/reportserver -e Mgmt2010
===== MyRSScript.rss =====
Public Sub Main()
Dim name As String = "DataSet1" ' DataSet name Dim parent As String = "/Data Sets" ' DataSet's parent path Dim dataSourceUrl As String = "/Data Sources/AdventureWorks" ' full path of Data Source
Dim fullpath As String = parent + "/" + name
RS.Credentials = System.Net.CredentialCache.DefaultCredentials
Try
'Set DataSet DataSource references
Dim referenceData() As ItemReferenceData = RS.GetItemReferences(fullpath, "DataSet")
Dim references(0) As ItemReference
Dim reference As New ItemReference()
reference.Name = referenceData(0).Name ' This should be "DataSetDataSource" Console.Writeline("Reference.Name: " & reference.Name)
Console.Writeline("Reference.Reference change from: " & referenceData(0).Reference & " to :" & dataSourceUrl)
reference.Reference = dataSourceUrl
references(0) = reference
RS.SetItemReferences(fullpath, references)
Console.Writeline("DataSet DataSource set successfully")
Catch e As SoapException
Console.WriteLine("Error : " + e.Detail.Item("ErrorCode").InnerText + " (" + e.Detail.Item("Message").InnerText + ")")
End Try
End Sub
===== Reference =====
ReportingService2010.SetItemReferences Method
http://technet.microsoft.com/en-us/library/reportservice2010.reportingservice2010.setitemreferences.aspx
Quote: Sets the catalog items associated with an item. This method applies to the Report and Dataset item types.
ReportingService2010.SetItemDataSources Method
http://technet.microsoft.com/en-us/library/reportservice2010.reportingservice2010.setitemdatasources.aspx
Quote: Sets the data sources for an item in a report server database or SharePoint library. This method applies to the Report and Model item types.
keyword: SSRS SSRS2008R2 RS2008R2 rs.exe SQL Server 2008 R2 SQL2008R2
Saturday, August 14, 2010
Subscribe to:
Post Comments (Atom)
Yes, it helped me a lot and gave a resolution for my two days search, the highlight of this blogs is "-e Mgmt2010" argument as part of rs utility
ReplyDeleters -i MyRSScript.rss -s http://localhost/reportserver -e Mgmt2010
thanks a lot
K.Singanan
I can get a DataSet to Reference a Data Source, but I need to have a Report Reference a Shared Data Set. Can you please explain how this would be done?
ReplyDeleteItemReferenceData[] dataSource = _rs.GetItemReferences("/" + Configuration.Default.ReportsInstallFolder + "/" + item.Name, "DataSource");
Deleteif (dataSource != null && dataSource.Length > 0 && !string.IsNullOrEmpty(dataSource[0].Name))
{
var sharedDataSource = new ItemReference
{
Name = Configuration.Default.ReportDataSourceName,
Reference = "/" + Configuration.Default.DataSourceInstallFolder + "/" + Configuration.Default.DataSourceName
};
_rs.SetItemReferences("/" + Configuration.Default.ReportsInstallFolder + "/" + item.Name, new[] { sharedDataSource });
Logger.WriteLine("Report " + item.Name + " bound to data source " + sharedDataSource.Name);
}
else
{
ItemReferenceData[] dataSets = _rs.GetItemReferences("/" + Configuration.Default.ReportsInstallFolder + "/" + item.Name, "DataSet");
if (dataSets != null && dataSets.Length > 0 && !string.IsNullOrEmpty(dataSets[0].Name))
{
var sharedDataSet = new ItemReference
{
Name = dataSets[0].Name,
Reference =
"/" + Configuration.Default.DataSetInstallFolder + "/" + dataSets[0].Name
};
_rs.SetItemReferences("/" + Configuration.Default.ReportsInstallFolder + "/" + item.Name, new[] {sharedDataSet});
Logger.WriteLine("Report " + item.Name + " bound to data set " + sharedDataSet.Name);
}
}
Thanks! Even after finding this it took me awhile to realize how critical the part is about the reference.Name being set to "DataSetDataSource". I was setting it to my DataSource name and kept getting an error about the data source not being found. Thanks for filling in the missing details to Microsoft's documentation on this.
ReplyDelete