2009-10-21 63 views
3

我有一堆报告作为RDL部署到SSRS。由于高安全性要求,db密码变化非常频繁。要跟上这些变化,并在数十次报告中修改数十项变成一项艰巨的任务。这导致我的问题...SQL报告服务 - 以编程方式设置数据源?

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

  • 这样做是否可以使用应用程序来修改报告本身,因为它位于服务器上?

  • 这可以通过在DS位于服务器上时从应用程序修改共享数据源来完成吗?

  • 是否可以通过在报告中嵌入脚本来完成从Web服务检索连接的脚本?

感谢

回答

4

这可以通过多种方式来完成,我认为最简单的一种是使用SSRS Web服务的API。 Web服务允许您操纵所有报告实体,包括Data Sources

作为此问题的解决方案,每次数据库密码更改(甚至使用某种触发器自动执行它)时,都可以使用对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); 
      } 
     } 
    } 
相关问题