簡體   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