重命名 SQL 报表服务文件






1.73/5 (7投票s)
编辑报表服务 2005 订阅作业并重命名渲染的文件
引言
在 SQL Server Reporting Services 2005 之后,你需要将报告文件渲染重命名到 \\Server\Public\Reports\Test 目录。
订阅已被执行并在此处创建了该文件。 这必须完成,以便报告的消费者可以拥有
带有日期的报告存档。 例如 01_02_thru_03_20_2008Production_RGU_Report 等等。
使用代码
解决方案: 有两种方法可以解决这个问题,但两者都解决了如何知道订阅服务
何时完成报告文件的创建的问题。 在本文中,我们将探讨这两种方案。方案 1:使用 SSIS 创建文件系统任务
来执行重命名。 方案 2:编写一个使用 sp_ReplaceFileOrDirNames 函数的 SQL 脚本来重命名文件。
图片已省略
两种方案都可以完成文件重命名的工作,但哪一种能够与订阅服务同步??? 我们即将找到答案。
通过登录到你的服务器,展开节点,然后右键单击
作业活动监视器,然后单击“查看作业活动”来访问屏幕,如下面的快照所示。 现在找到订阅事件的作业名称,
它可能类似于 6FD6B328-692B-4749-A6E1-E4E760CC0A5D。 双击它。
一旦你到达那里,你将能够执行一个新的步骤,删除、编辑或插入到该步骤中。
你想要点击“插入”,并按照提示完成新的步骤。
图片已省略
你将使用 master..xp_cmdshell
存储过程来重命名生产 Production_RGU_Report。 通过使用 T-SQL 存储过程重命名文件,
你可以避免使用订阅事件和程序员不得不事后每天重命名文件。
这是 T-SQL
SET @fn=REPLACE(convert(char(8),getdate(),1),'/','')
SET @cmd ='Ren \\Server\MyShared\New Folder\Report.xls \\chrd0dv02\MyShared\New Folder\Production_RGU_Reports '+@fn+'.xls'
Select @fn,@cmd
EXEC master..xp_cmdshell @cmd
图片已省略
You can type any name you want in the Step Name box. You can now select Transaction-SQL script (T-SQL)
for Type. Then Type in the SQL Script above of any appropriate script for renaming the files you want
to rename. Make sure that the paths
are correct for your system.
Image left out
Let us say that you had an SQL Server integrated service package store on this server or
any server on your network. Change Type to “SQL Server integrated service package” then
find the Package on the appropriate server. In the second
article I will discuss creating that Package to do the rename.
After adding the second step, make sure that you use the up down button to set
this new step that we have created as the second step after the report is run.
So now we have the first Step 6FD6B328-692B-4749-A6E1-E4E760CC0A5D, then the
second step Rename file. This job will run as a combined package.
关注点
编辑由 Reporting Service 2005 订阅创建的自动化作业。
历史
本周晚些时候,我将提交一篇文章,介绍如何创建 SSIS 包,以与订阅时间事件同步重命名文件。