[英]Programmatically exporting reports from SQL 2012 Reporting Services
[英]Sql reporting Services - Programmatically setting a datasource?
我有一堆報告作為RDL部署到SSRS。 由於高安全性要求,db密碼會經常更改。 要跟上變化並且不得不修改幾十個報告,這是一項艱巨的任務。 這引出了我的問題......
是否可以以編程方式為已部署的報告設置數據源或連接字符串?
這可以使用一個應用程序來完成,它可以修改報表中的某些內容,因為它位於服務器上嗎?
這可以通過在DS位於服務器上時從應用修改共享數據源來完成嗎?
是否可以通過在報表本身中嵌入一個腳本來完成,該腳本從Web服務中檢索連接?
謝謝
這可以通過多種方式完成,我認為最簡單的方法之一是使用SSRS Web服務的API。 Web服務允許您操作包括數據源在內的所有報告實體。
作為此問題的解決方案,每次數據庫密碼更改時,都可以使用對Web服務的調用來更新數據源憑據(甚至可以使用某種觸發器自動化它?)。
我在一個項目中做了類似的事情,其中必須在運行時生成,部署和操作RDL和數據源,並且它工作正常,因此更新數據源必須是可行的。
為Reporting Services端點添加服務引用( 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);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.