Answered by:
Programatically set report datasource

Question
-
I have a datasource created in my reporting server under a folder called DataSources.
I am uploading .rdl files using a console application. Is there any way to set the datasource of the uploaded .rdl programatically to datasource available in dataSources folder.
I am using reportingService webservice and C# to upload .rdls.
Mohan
Thursday, November 6, 2014 9:29 AM
Answers
-
Hello Mohan,
You can do that with the ReportingService2010.SetItemDataSources Method
See ReportingService2010 Class for all methods & properties.
Olaf Helper
[ Blog] [ Xing] [ MVP]- Edited by Olaf HelperMVP Thursday, November 6, 2014 9:45 AM
- Proposed as answer by Simon_HouMicrosoft contingent staff Friday, November 7, 2014 6:15 AM
- Marked as answer by Simon_HouMicrosoft contingent staff Monday, November 17, 2014 2:11 AM
Thursday, November 6, 2014 9:44 AM
All replies
-
Hello Mohan,
You can do that with the ReportingService2010.SetItemDataSources Method
See ReportingService2010 Class for all methods & properties.
Olaf Helper
[ Blog] [ Xing] [ MVP]- Edited by Olaf HelperMVP Thursday, November 6, 2014 9:45 AM
- Proposed as answer by Simon_HouMicrosoft contingent staff Friday, November 7, 2014 6:15 AM
- Marked as answer by Simon_HouMicrosoft contingent staff Monday, November 17, 2014 2:11 AM
Thursday, November 6, 2014 9:44 AM -
Hopefully this is helpful:
using GetPropertiesSample.ReportService2010;
using System.Collections.Generic; //<== required for LISTS
namespace GetPropertiesSample
{
class Program
{
static void Main(string[] args)
{
ResetTheDataSource_for_a_Report();
}
private static void ResetTheDataSource_for_a_Report()
{
//from: http://stackoverflow.com/questions/13144604/ssrs-reportingservice2010-change-embedded-datasource-to-shared-datasource
ReportingService2010 rs = new ReportingService2010();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
string reportPathAndName = "/0_Contacts/207_Practices_County_CareManager_Role_ContactInfo";
List<ReportService2010.ItemReference> itemRefs = new List<ReportService2010.ItemReference>();
ReportService2010.DataSource[] itemDataSources = rs.GetItemDataSources(reportPathAndName);
foreach (ReportService2010.DataSource itemDataSource in itemDataSources)
{
ReportService2010.ItemReference itemRef = new ReportService2010.ItemReference();
itemRef.Name = itemDataSource.Name;
itemRef.Reference = "/DataSources/SharedDataSource_DB2_CRM";
itemRefs.Add(itemRef);
}
rs.SetItemReferences(reportPathAndName, itemRefs.ToArray());
}
}
}Sunday, March 27, 2016 4:08 PM