繁体   English   中英

如何通过SQL Query在SSRS报表中为特定报表创建新快照

[英]How to create new snapshot in SSRS report by SQL Query for particular report

通过用户界面单击“新快照”按钮,可以很容易地在报表服务器上为报告创建快照,但是我只需要使用SQL Query来创建新快照。 这意味着将使用什么SQL查询,而无需使用用户界面就可以在报表服务器上为特定报表创建新快照? 一世

不建议直接点击ReportServer数据库。 生成SSRS报告快照的首选方法是使用C#调用CreateReportHistorySnapshot API方法。 但是,如果必须使用SQL,则请查看AddEvent ReportServer存储过程。

exec [ReportServer].dbo.AddEvent @EventType='ReportExecutionUpdateSchedule', @EventData='<InsertReportIDHere>'

此处此处可以找到更多信息。 下面是一个示例SQL脚本,该脚本可以每天为给定的报告生成一个新的快照。

declare @Path varchar(425)
set @Path = '/SSRS Testing and Training/Test_snapshot' -- the name of my linked report which renders from a snapshot

declare @EventData uniqueidentifier
select @EventData = (select ItemID from Catalog where Path = @Path) 

-- make a new snapshot in History table
exec ReportServer.dbo.AddEvent 'ReportHistorySchedule', @EventData 

-- !!!! wait until Reporting Services figures out that it has an event to process (it actually takes 5sec)
waitfor delay '00:00:10' 

-- take a snapshot ID from a newly created row in History table
declare @SnapshotDataID uniqueidentifier
select @SnapshotDataID = (select SnapshotDataID from history WHERE ReportID = @EventData)

-- set a date for a new Snapshot in Catalog table
-- use getdate() instead (select SnapshotDate from history WHERE ReportID = @EventData) because otherwise you'll get a UTC date for "last run date" in Report Manager which can confuse your users 
declare @SnapshotDate datetime
select @SnapshotDate = getdate() 

-- run a RS stored procedure which updates SnapshotDataID in Catalog table and some other necessary things
exec UpdateSnapshot @Path,@SnapshotDataID,@SnapshotDate

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM