Skip to main content
 首页 » 编程设计

c#之SSRS 以编程方式设置 "Credentials stored securely in the report server"

2024年08月06日31lhb25

我正在尝试通过我的客户端应用程序设置给定的 RDL 报告以使用嵌入式数据源。我正在使用 ReportingService2005 类与 SSRS 进行交互。我需要将嵌入式数据源设置为使用“安全地存储在报表服务器中的凭据”并指定用户名和密码。

谢谢!

请您参考如下方法:

我通过首先发布 RDL,然后调用 ReportingService2005 GetItemDataSources() 方法解决了这个问题。然后我修改了该数据源,随后调用 SetItemDataSources() 将更改保存到 SSRS 中。下面是我使用的代码片段:

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); 
 }