【发布时间】:2015-06-11 10:56:37
【问题描述】:
有人知道可以让我将许多 RDL 文件部署到许多 SSRS 服务器的工具吗?
多达 50 份报告给 20 多台服务器。每个 ssrs 服务器都有相同的结构。
感谢您的帮助
汉斯
【问题讨论】:
-
您是否能够转移您的报告?
标签: reporting-services deployment
有人知道可以让我将许多 RDL 文件部署到许多 SSRS 服务器的工具吗?
多达 50 份报告给 20 多台服务器。每个 ssrs 服务器都有相同的结构。
感谢您的帮助
汉斯
【问题讨论】:
标签: reporting-services deployment
好消息,有几种方法可以做到这一点,这里是从低级到高级的列表:
创建一个使用 SSRS Web 服务的自定义应用程序
您可以使用 Reporting Services Web 服务来执行此任务但我不建议您这样做,除非您有其他方式无法满足的特定需求。
原因是这需要一些时间,没有必要重新发明轮子。
有 2 个 Web 服务可用,要管理报表服务器项目,您将需要 ReportingService2010 或 ReportingService2005,具体取决于您的报表服务实例。
更多关于如何使用这些网络服务here的细节。
手动编写脚本
您可以编写脚本 (.rss) 并使用 RS.exe 导入它们。
该工具基于前面提到的 Web 服务。
rs.exe 实用程序处理您在输入文件中提供的脚本。 使用此实用程序自动化报表服务器部署和 管理任务。
请注意,SQL Server 2008 R2+ 支持 Sharepoint 模式。
这是一篇 MSDN 文章,其中提供了更多详细信息:
Sample Reporting Services rs.exe Script to Migrate Content between Report Servers。
使用工具生成脚本
这是我最喜欢的一个,已经编写了几个工具来编写来自服务器 A 的项目并将其恢复到服务器 B,其中之一是 RSScripter。
你可以在here找到使用教程。
内部使用RS.exe,使用GUI的步骤是:
还有微软的Reporting Service Migration Tool,好像有一些附加功能,但我没测试过。
【讨论】:
您可以编写自己的程序来执行此操作,如下所示:
private static string UploadReportFiles(string[] args)
{
string results = String.Empty;
string filesFolder = String.Empty;
string fileName = String.Empty;
if (args.Count() > 14)
{
try
{
//args[0] - Command
//args[1] - Switch Should be /S Server Name
string serverName = args[2];
//args[3] - Switch Should be /U User Name
string userName = args[4];
//args[5] - Switch Should be /P User Password
string password = args[6];
//args[7] - Switch Should be /M Server Manager Folder
string managerFolder = args[8];
//args[9] - Switch Should be /R Server Reports Folder
string reportFolder = args[10];
//args[11] - Switch Should be /D Server Data Sources Folder
string dataSourceFolder = args[12];
//args[13] - Switch Should be /F Files Folder
filesFolder = args[14];
ReportingService2005 rs = new ReportingService2005();
string url = <ProjectNamespace>.Properties.Settings.Default.RDLManager_ReportService_ReportingService2005.Replace("localhost", serverName).Replace("ReportServer", managerFolder);
rs.Url = url;
NetworkCredential networkCredential = new NetworkCredential(userName, password);
rs.Credentials = networkCredential;
CatalogItem[] rootItems = rs.ListChildren("/", false);
IEnumerable<string> rootNames = from x in rootItems.AsEnumerable()
select x.Name;
if (!rootNames.Contains(reportFolder))
{
rs.CreateFolder(reportFolder, "/", null);
}
CatalogItem[] items = rs.ListChildren("/" + reportFolder, false);
IEnumerable<string> itemNames = from x in items.AsEnumerable()
select x.Name;
string[] reportFiles = Directory.GetFiles(filesFolder);
foreach (string file in reportFiles)
{
string returnMessage = String.Empty;
try
{
if (file.EndsWith(".rdl") && !file.Contains("Backup"))
{
FileInfo fi = new FileInfo(file);
fileName = fi.Name.Replace(".rdl", "");
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
string reportFilePath = Path.Combine(filesFolder, fileName);
using (FileStream fs = new FileStream(reportFilePath + ".rdl", FileMode.Open))
{
// Read the source file into a byte array.
byte[] bytes = new byte[fs.Length];
int numBytesToRead = (int)fs.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
// Read may return anything from 0 to numBytesToRead.
int n = fs.Read(bytes, numBytesRead, numBytesToRead);
// Break when the end of the file is reached.
if (n == 0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
numBytesToRead = bytes.Length;
string reportName = fileName.Replace(".rdl", "");
Warning[] publishErrors;
if (itemNames.Contains(reportName))
{
System.Console.WriteLine("Uploading Report File - " + fileName);
string report = "/" + reportFolder + "/" + reportName;
DataSource[] existingDataSources = null;
DataSource existingDataSource = null;
existingDataSources = rs.GetItemDataSources(report);
if (null != existingDataSources)
{
existingDataSource = existingDataSources[0];
}
publishErrors = rs.SetReportDefinition(report, bytes);
DataSource[] publishedDataSources = null;
publishedDataSources = rs.GetItemDataSources(report);
if (null != existingDataSource)
{
List<DataSource> replacementDataSources = new List<DataSource>();
DataSourceReference dsr = new DataSourceReference();
string dataSourcePath = "/" + dataSourceFolder + "/" + existingDataSource.Name;
dsr.Reference = dataSourcePath;
foreach (DataSource publishedDataSource in publishedDataSources)
{
DataSource ds = new DataSource();
ds.Item = (DataSourceDefinitionOrReference)dsr;
ds.Name = publishedDataSource.Name;
replacementDataSources.Add(ds);
}
rs.SetItemDataSources(report, replacementDataSources.ToArray());
}
}
else
{
publishErrors = rs.CreateReport(reportName, "/" + reportFolder, true, bytes, null);
fileName = fileName + " - NEW REPORT UPDATE DATASOURCE MANUALLY!";
System.Console.WriteLine("Uploading Report File - " + fileName);
}
if (null != publishErrors)
{
foreach (Warning w in publishErrors)
{
if (w.Severity != "Warning")
{
returnMessage = "Warning: ";
returnMessage = returnMessage + w.Message;
}
}
}
}
}
}
catch (SoapException ex)
{
returnMessage = "Error Uploading File:" + fileName + " Exception:" + ex.Detail.InnerXml.ToString();
}
catch (IOException ex)
{
returnMessage = "Error Uploading File:" + fileName + " Exception:" + ex.Message;
}
catch (Exception ex)
{
returnMessage = "Error Uploading File:" + fileName + " Exception:" + ex.Message;
}
string logLineItem = "Uploaded " + fileName + " to " + serverName + ". " + returnMessage;
LogItem.LogMessage(logLineItem, filesFolder);
}
results = "Upload Complete!";
}
catch (SoapException ex)
{
results = "Error Uploading Files Exception:" + ex.Detail.InnerXml.ToString();
}
catch (IOException ex)
{
results = "Error Uploading Files Exception:" + ex.Message;
}
catch (Exception ex)
{
results = "Error Uploading Files Exception:" + ex.Message;
}
}
else
{
ShowHelpText();
}
if (!String.IsNullOrEmpty(filesFolder))
{
LogItem.LogMessage(results, filesFolder);
}
return results;
}
【讨论】: