user3272684
user3272684

Reputation: 51

SSRS Set "Credentials stored securely in the report server" programmatically

I am trying to set a given RDL report to use an embedded data source using my client application. I am using the ReportingService2005 class to interact with SSRS. I need to set the embedded data source to use "Credentials stored securely in the report server" and specify the username and password.

Thank you!

Upvotes: 1

Views: 1261

Answers (1)

user3272684
user3272684

Reputation: 51

I solved the issue by first publishing the RDL, then calling into the ReportingService2005 GetItemDataSources() method. I then modified that datasource and subsequently called SetItemDataSources() to save the changes into SSRS. Below is a snippet of the code I accomplished this with:

var reportItem = report.TargetFolder + "/" + report.Name;
var dataSources = new DataSource[0];

dataSources = rs.GetItemDataSources(reportItem);
if (dataSources.Any())
{
     var dataSource = (DataSourceDefinition)dataSources.First().Item;
     dataSource.CredentialRetrieval = CredentialRetrievalEnum.Store;
     dataSource.UserName = SsrsUsername;
     dataSource.Password = SsrsPassword;

     rs.SetItemDataSources(reportItem, dataSources);
 }

Upvotes: 3

Related Questions