我们可以使用Shell脚本语言触发SSRS报告吗?我知道RS.exe在通过Shell脚本触发SSRS报告时会有用吗?
预先感谢。
答案 0 :(得分:0)
您可以通过SQL触发报表订阅,因此我想您可以通过Shell脚本来实现。
报告订阅是服务器上的作业,因此您需要知道jobID才能工作。然后,您可以通过以下方式触发:
use msdb;
exec sp_start_job @job_name = '';
job_name
来自ReportServer数据库中的表dbo.Schedule
。您可以使用类似此脚本的内容来找到它:
declare @SearchString as nvarchar(100) = '';
with [SubscriptionXML] as
(
select
sb.SubscriptionID,
cast(sb.ExtensionSettings as xml) as [ExtensionSettingsXML]
from dbo.Subscriptions as [sb]
inner join dbo.[Catalog] as [c] on sb.Report_OID = c.ItemID
where c.[Name] like '%' + @SearchString + '%'
),
[SettingsCTE] as
(
select
sxml.SubscriptionID,
isnull([xml].Settings.[value]('(./*:Name/text())[1]', 'nvarchar(1024)'), 'Value') as [SettingName],
[xml].Settings.[value]('(./*:Value/text())[1]', 'nvarchar(max)') as [SettingValue]
from [SubscriptionXML] as [sxml]
cross apply sxml.ExtensionSettingsXML.nodes('//*:ParameterValue') as [xml](Settings)
)
select
s.ScheduleID as [SQLAgentJobName],
c.[Name] as [ReportName],
scteSubject.SettingValue as [Subject],
scteTo.SettingValue as [To],
scteBCC.SettingValue as [BCC],
case s.RecurrenceType
when 1
then 'Once'
when 2
then 'Hourly'
when 3
then 'Daily'
when 4
then 'Weekly'
else 'Monthly'
end as [SubscriptionScheduleType],
c.[Path] as [ReportPath],
s.[LastRunTime]
from dbo.ReportSchedule as [rs]
inner join dbo.Schedule as [s] on s.ScheduleID = rs.ScheduleID
inner join dbo.[Catalog] as [c] on c.ItemID = rs.ReportID
left join [SettingsCTE] as [scteSubject] on scteSubject.SubscriptionID = rs.SubscriptionID
and scteSubject.SettingName = 'Subject'
left join [SettingsCTE] as [scteTo] on scteTo.SubscriptionID = rs.SubscriptionID
and scteTo.SettingName = 'To'
left join [SettingsCTE] as [scteBCC] on scteBCC.SubscriptionID = rs.SubscriptionID
and scteBCC.SettingName = 'BCC'
where c.[Name] like '%' + @SearchString + '%';
一旦有了job_name
,您就可以在Shell脚本中引用它。然后,您需要做的就是从脚本中触发sp_start_job
的SQL位。