PowerShell 可以编写 SQL Server Reporting Services RDL 文件脚本吗?

发布于 2024-07-11 21:07:52 字数 1399 浏览 7 评论 0原文

是否可以使用 PowerShell 在 SQL Server 2008 中编写 SQL Server Reporting Services rdl 文件脚本? 如果是这样,有人可以提供执行此操作的代码示例吗? 这将是使用第三方工具编写由我的商业智能部门之外的业务用户创建的 RDL 文件的有用替代方案。

术语“脚本输出”的澄清

通过“脚本输出”,我的意思是我想为服务器上的每个报告自动生成底层 RDL 文件。 例如,当您在 BIDS 中编写报告代码时,您将生成一个 RDL 文件。 当您将文件部署到服务器时,该文件会以某种方式导入到 SQL Server ReportServer 数据库中,并且它不再是单独的物理 RDL 文件。 我想以 RDL 文件格式从服务器提取所有报告。

我已经使用 RSScripter 工具将报告提取为 RDL 文件,因此我知道可以使用 PowerShell 以外的工具。 我特别想知道是否可以使用 PowerShell 来完成此操作,如果可以,请获取执行此操作的代码示例。

澄清为什么我想要生成 RDL 版本的报告

为什么将报告“脚本化”到 RDL 文件很重要? 我想每晚将 RDL 文件签入我的源代码控制系统一次,以跟踪我的商业智能部门之外的用户创建的所有报告。 自从我们在 BIDS 中开发报告以来,我已经跟踪了我的部门生成的所有报告,但我无法跟踪在线报告生成器工具中构建的报告的版本控制历史记录。

澄清为什么使用 POWERSHELL 而不是其他东西

  1. 好奇心。 我有一个问题,我知道可以通过两种方法(API 或 RSSCripter)之一来解决,我想知道是否可以通过第三种方法来解决。

  2. 有机会通过 PowerShell 扩展我的问题解决工具。 使用 PowerShell 解决此问题可能为学习如何使用 PowerShell 解决我尚未尝试解决的其他问题奠定基础。

  3. PowerShell 对于我和我的团队来说更容易理解。 一般来说,我和我的团队成员比 .NET 代码更容易理解 PowerShell 代码。 虽然我知道这个问题可以通过使用 API 的一些 .NET 代码来解决(这毕竟是 RSScripter 的工作原理),但我觉得我们编写和维护 PowerShell 脚本会更容易。 我还意识到 PowerShell 脚本可能会使用 .NET 代码,但我希望 PowerShell 已经能够以某种方式将报表视为对象,这样我就不必使用 Reporting Services API 来提取文件。< /p>

  4. RSScripter 尚不支持 2008。 过去,我使用 RSScript 编写报告脚本。 不幸的是,它似乎还不支持 2008 年。 这意味着我现在必须针对 API 编写代码,因为这是我目前知道如何以自动无人值守方式提取文件的唯一方法。

Is it possible to use PowerShell to script out SQL Server Reporting Services rdl files in SQL Server 2008? If so, can someone provide a code example of doing this? This would be a useful replacement for using a 3rd party tool to script out RDL files created by business users outside of my Business Intelligence department.

CLARIFICATION OF THE TERM "SCRIPT OUT"

By "script out", I mean I would like to automatically generate the underlying RDL file for each report on the server. For instance, when you code report in BIDS, you are generating a RDL file. When you deploy the file to the server, the file is somehow imported into the SQL Server ReportServer database and it is no longer a separate physical RDL file. I would like to extract all the reports from the server in a RDL file format.

I've used the RSScripter tool to extract the reports as RDL files, so I know it is possible using tools other than PowerShell. I would specifically like to know if it is possible to do it using PowerShell and, if so, get a sample of the code to do it.

CLARIFICATION ON WHY I WANT TO GENERATE RDL VERSIONS OF REPORTS

Why is it important to "script out" the reports to RDL files? I would like to check-in the RDL files to my source control system once a night to keep track of all reports created by users outside of my Business Intelligence department. I already keep track of all reports generated by my department since we develop our reports in BIDS, but I can't keep track of versioning history on reports built in the online Report Builder tool.

CLARIFICATION ON WHY POWERSHELL AND NOT SOMETHING ELSE

  1. Curiosity. I have a problem that I know can be solved by one of two methods (API or RSSCripter) and I would like to know if it can be solved by a 3rd method.

  2. Opportunity to expand my problem solving toolbet via PowerShell. Using PowerShell to solve this problem may provide the foundation for learning how to use PowerShell to solve other problems that I haven't tried to solve yet.

  3. PowerShell is easier to understand for my team and me. In general, my team members and I can understand PowerShell code more easily than .NET code. Although I know this problem can be solved with some .NET code using the API (that's how RSScripter works after all), I feel it will be easier for us to code and maintain a PowerShell script. I also realize a PowerShell script will probably use .NET code, but I'm hoping PowerShell will already be able to treat the reports like objects in some way so I won't have to use the Reporting Services API to extract the files.

  4. RSScripter doesn't support 2008 yet. In the past, I've used RSScript to script out reports. Unfortunately, it doesn't appear to support 2008 yet. This means I have to write code against the API right now since that's the only way I present know how to extract the files in an automated unattended manner.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

我恋#小黄人 2024-07-18 21:07:52

有点晚了,但你可以开始

这个 PowerShell 脚本:
1. 连接到您的报表服务器
2. 创建与报表服务器中相同的文件夹结构
3. 将所有 SSRS 报告定义 (RDL) 文件下载到各自的文件夹

https://sqlbelle.wordpress.com/2011/03/28/how-to-download-all-your-ssrs-report-definitions -rdl-files-using-powershell/

a little late, but here you go

This PowerShell script :
1. Connects to your report server
2. Creates the same folder structure you have in your Report Server
3. Download all the SSRS Report Definition (RDL) files into their respective folders

https://sqlbelle.wordpress.com/2011/03/28/how-to-download-all-your-ssrs-report-definitions-rdl-files-using-powershell/

守望孤独 2024-07-18 21:07:52

PowerShell 不为此提供任何本机的 PowerShell 式功能,不。 您可以在 PowerShell 中执行此操作(如前面的答案中所述),只是因为 PowerShell 可以访问底层 Framework 类。 正如您在对上一个答案的评论中指出的那样,这与在 C# 或 VB 中使用 API 没有什么不同。

SQL Server 团队尚未提供太多 PowerShell 特定的内容。 他们主要依赖 .NET 和 T-SQL 作为“脚本语言”。

PowerShell doesn't provide any native, PowerShell-esque functionality for this, no. You can do this in PowerShell (as noted in the previous answer) only because PowerShell can access the underlying Framework classes. As you noted in your comment to the previous answer, it's no different from using the API in C# or VB.

The SQL Server team has not yet provided much in the way of PowerShell-specific stuff. They're primarily relying on .NET and T-SQL as "scripting languages."

行至春深 2024-07-18 21:07:52

我刚刚意识到 ReportServer.dbo.Catalog 中的内容列包含图像格式的定义。 我编写了以下代码将其转换为可读文本:

SELECT CONVERT(VARCHAR(MAX), CONVERT(NVARCHAR(MAX), CONVERT(XML, CONVERT(VARBINARY(MAX), Content))))
FROM [ReportServer].[dbo].[Catalog]
WHERE Type = 2

通过上述代码,我现在可以自动将结果写入平面文件,然后将该文件导入到我的版本控制系统中。

I just realized the Content column in the ReportServer.dbo.Catalog contains the definition in an Image format. I wrote the following code to convert it to readable text:

SELECT CONVERT(VARCHAR(MAX), CONVERT(NVARCHAR(MAX), CONVERT(XML, CONVERT(VARBINARY(MAX), Content))))
FROM [ReportServer].[dbo].[Catalog]
WHERE Type = 2

With the above code, I can now automate writing the results to a flat file and then import the file into my version control system.

计㈡愣 2024-07-18 21:07:52

任何支持 .Net 的东西都可以做到这一点。 请参阅此 Stackoverflow 帖子了解一些信息API 文档的链接。 该过程实际上相当简单 - API 调用上传或下载 .rdl 文件。

报表模型有点复杂。 如果您上传新的报告模型,则必须获取相关报告(再次调用 API)并重新连接数据源。 再说一次,不是非常费力。

Powershell 应该可以很好地做到这一点。 我已经使用 IronPython 和 C# 完成了不同的工作。 还有一个名为 rs.exe 的工具,它采用 vb.net 脚本,在其顶部和尾部添加一些包含内容,并在幕后编译和运行它。

Anything that supports .Net can do this. See this Stackoverflow posting for some links to the API docs. The process is actually fairly straightforward - the API has a call to upload or download the .rdl file.

Report models are a bit more fiddly. You have to get the dependent reports (again an API call) and re-connect the data source if you upload a new report model. Again, not terribly strenuous.

Powershell should do this fine. I've variously done this with IronPython and C#. There's a also a tool called rs.exe that takes a vb.net script, tops and tails it with some includes and compiles and runs it behind the scenes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文