SQL Reporting Services - 如何以编程方式设置数据源?

3
我已经将一堆报告部署为RDL到SSRS。由于高安全要求,数据库密码非常频繁更改。随着不断地修改数十个报告,这已成为一项巨大任务。这引出我的问题...

是否可以以编程方式为已部署的报告设置数据源或连接字符串?

  • 是否可以使用一个应用程序来修改服务器上的报告本身中的某些内容来完成此操作?

  • 是否可以通过从应用程序修改共享数据源来完成此操作,因为数据源位于服务器上?

  • 是否可以通过在报表本身中嵌入检索连接的脚本(例如来自Web服务)来完成此操作?

谢谢

2个回答

4
这可以通过多种方式实现,我认为其中最简单的一种是使用SSRS Web服务的API。Web服务允许您操作所有报告实体,包括数据源

作为解决此问题的方案,可以在每次更改数据库密码时使用Web服务调用更新数据源凭据(甚至使用某种触发器自动化它?)。

我在一个需要在运行时生成、部署和操作RDL和数据源的项目中做了类似的事情,它运行良好,因此更新数据源必须是可行的。


0
在您的项目中添加服务引用以连接到报表服务端点(http://ReportServerHost.mydomain.tld/ReportServer/ReportService2005.asmx)。使用以下代码修改数据源密码:

    public static void ChangeDataSourcePassword(string dataSourcePath, string password)
    {
        using (ReportingService2005SoapClient reportingService = new ReportingService2005SoapClient())
        {
            reportingService.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

            try
            {  
                ServerInfoHeader serverInfo = null;
                DataSourceDefinition dataSourceDefinition = null;

                serverInfo = reportingService.GetDataSourceContents(dataSourcePath, out dataSourceDefinition);
                dataSourceDefinition.Password = password;
                serverInfo = reportingService.SetDataSourceContents(null, dataSourcePath, dataSourceDefinition);
            }
            catch (FaultException ex)
            {
                // Do something with the exception. Rethrow it and/or show it to the user.
                Console.WriteLine(string.Format("Failed to change the password on {0}: {1}", dataSourcePath, ex.Message));
                throw new ApplicationException("Failed to change the password on the Data Source.", ex);
            }
        }
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接