使用 T-SQL 修改 SSRS 订阅
Amend SSRS Subscriptions with T-SQL
是否可以使用 T-SQL 修改现有的 SSRS 订阅?我有一个场景,许多订阅由于服务器错误而无法发送。我想将它们全部移动到一个新的 date/time,然后再将它们全部移动回来。
当我遇到非 运行 报告的问题时,我通常使用带有订阅 ID 的 EXEC dbo.AddEvent 重新启动订阅。
SELECT e.name
, e.path
, d.description
, a.SubscriptionID
, laststatus
, LastRunTime
, date_modified
, 'EXEC dbo.AddEvent @EventType = ''TimedSubscription'', @EventData = '' ' + CAST(a.SubscriptionID AS VARCHAR(100)) + ''''
FROM
ReportServer.dbo.ReportSchedule a
JOIN msdb.dbo.sysjobs b ON CAST(a.ScheduleID AS NVARCHAR(200)) = b.name
JOIN ReportServer.dbo.Subscriptions d ON a.SubscriptionID = d.SubscriptionID
JOIN ReportServer.dbo.Catalog e ON d.report_oid = e.itemid
WHERE d.LastStatus LIKE 'Fail%'
AND eventtype = 'TimedSubscription'
ORDER BY e.name
回答你的问题...
Can existing SSRS Subscriptions be amended using T-SQL?
我不确定您是否可以使用 TSQL 更改订阅。我用 SQL 提取了订阅...请参阅我用 SQL 查询发布的这个答案:is there a way to query future SSRS subscription schedules?.
我最近经常使用 PowerShell
来编写管理自动化脚本。您可以为 PowerShell from Microsoft on Github 安装 ReportingServicesTools module
。我建议您尝试学习它。在我看来,它看起来很酷,到目前为止,根据我的测试,它似乎具有一些很有前途的功能。
- RedGlue: Installing ReportingServicesTools for Powershell
- RedGlue: Powershell and SSRS Subscriptions or SQL Server Central: Powershell and SSRS Subscriptions
注意:我有 Windows 7,它随 Powershell 版本 2 一起提供。我必须将我的 Powershell 升级到版本 4 才能使用这些说明安装 RS 模块:1) MS Installing Windows PowerShell, 2) How to check the PowerShell version & install a new version. To check your version of Powershell execute either of these commands... $PSVersionTable.PSVersion
or $psversiontable
, as seen in this post: Determine installed PowerShell version.
I want to move all of them to a new date/time, and afterwards move
them all back again.
PowerShell 的目的不仅仅是查看对象,您还可以修改它们。
RSTools posh 模块有很多相关的 cmdlet,包括:Get-RsSubscripton
、Set-RsSubscripton
、Copy-RsSubscripton
、Export-RsSubscripton
、Import-RsSubscripton
、New-RsSubscripton
、Remove-RsSubscripton
。下面我使用 GET 和 SET 在基于单个文件夹的服务器上演示了 Help
和 Subscription Properties
。
Set-RsSubscription cmdlet 具有可让您轻松更改订阅属性的参数 StartDateTime、EndDate、所有者。然后是参数SubProperties,目前还不确定这个是什么。
演示:Powershell 代码
声明变量
$reportServerUri_src = "http://gcod049/ReportServer"
$reportServerUri_tgt = "http://gcod050/ReportServer"
查找订阅(一个文件夹 returns 2 个订阅.. 'd8e0decf-86f3-49cb-896f-3af644be1be3' 和 '4c1539c4-9e0f-42c4-aace-b493c96ec2e4')
Get-RsSubscription -ReportServerUri $reportServerUri_src -RsItem "/fsqa"
更改特定订阅的开始日期时间
Get-RsSubscription -ReportServerUri $reportServerUri_src -Path "/fsqa" | Where-Object {$_.SubscriptionId -eq '4c1539c4-9e0f-42c4-aace-b493c96ec2e4'} | Set-RsSubscription -StartDateTime "2/13/2019 1:20pm" -verbose
更改整个文件夹的开始日期时间
Get-RsSubscription -ReportServerUri $reportServerUri_src -Path "/fsqa" | Set-RsSubscription -StartDateTime "2/13/2019 1:20pm" -verbose
(奖励)将所有订阅从一个服务器文件夹移动到另一个(gcod050 "/fsqa" 到 gcod049 "/fsqa")
--移动订阅(From/To文件夹)
注意,2/13/19:A bug 目前正在解决这个问题。
Get-RsSubscription -ReportServerUri $reportServerUri_src -RsItem "/fsqa" | Copy-RsSubscription -ReportServerUri $reportServerUri_tgt -RsItem "/fsqa" -verbose
--创建文件夹
New-RsFolder -ReportServerUri $reportServerUri_tgt -RsFolder '/' -FolderName 'FSQA' -Description 'Reports for Food Saftey Quality Asurance department' -Verbose
--- Messages output from '-Verbose' parameter ---
VERBOSE: Establishing proxy connection to http://gcod050/ReportServer/ReportService2010.asmx...
VERBOSE: Creating folder FSQA...
VERBOSE: Folder FSQA created successfully!
--移动报告(From/To文件夹)
嗯...我不太明白 PS 模块命令将报告从服务器 A 移动到服务器 B。通过 Powershell 发布报告的命令似乎都适用于本地文件 (Link Name: Article). Here is an easy-to-use tool you can download for moving reports from ServerA to ServerB, SSRS 2008 R2 to SSRS 2016 Migration。
NOTE:
The "Content" cmdlets (based upon the documentation) appear to move files from/to a directory, instead of ServerA to ServerB
CMD:
get-command -module ReportingServicesTools *cont*
OUTPUT:
CommandType Name ModuleName
----------- ---- ----------
Function Get-RsFolderContent ReportingServicesTools
Function Out-RsFolderContent ReportingServicesTools
Function Out-RsRestFolderContent ReportingServicesTools
Function Write-RsFolderContent ReportingServicesTools
Function Write-RsRestFolderContent ReportingServicesTools
演示:截图
POSH_Get-RsSubscription -ReportServerUri $reportServerUri -Path fsqa.png
Get-RsSubscription -ReportServerUri $reportServerUri -Path "/fsqa"
POSH_get-help得到-RsSubscription.png
get-help Get-RsSubscription
POSH_Get-Help Set-RsSubscription -详细
Get-Help Set-RsSubscription -detailed
POSH_Get-Help复制-RsSubscription.png
Get-Help Copy-RsSubscription
POSH_Get-Command -模块 ReportingServicesTools.png
Get-Command -Module ReportingServicesTools
更新 2019 年 2 月 12 日星期二 16:27:33.22
我发现了 2017 年 8 月的另一篇文章,其中讨论了如何通过 PowerShell 以编程方式修改 SSRS 订阅--Warrenestes.com "Update Multiple SSRS Subscriptions"。在他的网站上,他使用 New-WebServiceProxy 开发了自己的 PoSH 函数,这对我来说看起来有点复杂。但他确实在他关于 cmdlet SET-RSSUBSCRIPTION 的文章中说过:
Edit: This is now part of the official Microsoft ReportingServicesTools PowerShell module.
This a brand new function, which was recently renamed from Update to Set-RsSubscription!!!!!.
他说了这个...
I did find a post on dba.stackexchange referencing the real [EndDate] from a column
in **dbo.Subscritions** called… wait for the descriptive name... **[MatchData]**!
是否可以使用 T-SQL 修改现有的 SSRS 订阅?我有一个场景,许多订阅由于服务器错误而无法发送。我想将它们全部移动到一个新的 date/time,然后再将它们全部移动回来。
当我遇到非 运行 报告的问题时,我通常使用带有订阅 ID 的 EXEC dbo.AddEvent 重新启动订阅。
SELECT e.name
, e.path
, d.description
, a.SubscriptionID
, laststatus
, LastRunTime
, date_modified
, 'EXEC dbo.AddEvent @EventType = ''TimedSubscription'', @EventData = '' ' + CAST(a.SubscriptionID AS VARCHAR(100)) + ''''
FROM
ReportServer.dbo.ReportSchedule a
JOIN msdb.dbo.sysjobs b ON CAST(a.ScheduleID AS NVARCHAR(200)) = b.name
JOIN ReportServer.dbo.Subscriptions d ON a.SubscriptionID = d.SubscriptionID
JOIN ReportServer.dbo.Catalog e ON d.report_oid = e.itemid
WHERE d.LastStatus LIKE 'Fail%'
AND eventtype = 'TimedSubscription'
ORDER BY e.name
回答你的问题...
Can existing SSRS Subscriptions be amended using T-SQL?
我不确定您是否可以使用 TSQL 更改订阅。我用 SQL 提取了订阅...请参阅我用 SQL 查询发布的这个答案:is there a way to query future SSRS subscription schedules?.
我最近经常使用 PowerShell
来编写管理自动化脚本。您可以为 PowerShell from Microsoft on Github 安装 ReportingServicesTools module
。我建议您尝试学习它。在我看来,它看起来很酷,到目前为止,根据我的测试,它似乎具有一些很有前途的功能。
- RedGlue: Installing ReportingServicesTools for Powershell
- RedGlue: Powershell and SSRS Subscriptions or SQL Server Central: Powershell and SSRS Subscriptions
注意:我有 Windows 7,它随 Powershell 版本 2 一起提供。我必须将我的 Powershell 升级到版本 4 才能使用这些说明安装 RS 模块:1) MS Installing Windows PowerShell, 2) How to check the PowerShell version & install a new version. To check your version of Powershell execute either of these commands... $PSVersionTable.PSVersion
or $psversiontable
, as seen in this post: Determine installed PowerShell version.
I want to move all of them to a new date/time, and afterwards move them all back again.
PowerShell 的目的不仅仅是查看对象,您还可以修改它们。
RSTools posh 模块有很多相关的 cmdlet,包括:Get-RsSubscripton
、Set-RsSubscripton
、Copy-RsSubscripton
、Export-RsSubscripton
、Import-RsSubscripton
、New-RsSubscripton
、Remove-RsSubscripton
。下面我使用 GET 和 SET 在基于单个文件夹的服务器上演示了 Help
和 Subscription Properties
。
Set-RsSubscription cmdlet 具有可让您轻松更改订阅属性的参数 StartDateTime、EndDate、所有者。然后是参数SubProperties,目前还不确定这个是什么。
演示:Powershell 代码
声明变量
$reportServerUri_src = "http://gcod049/ReportServer"
$reportServerUri_tgt = "http://gcod050/ReportServer"
查找订阅(一个文件夹 returns 2 个订阅.. 'd8e0decf-86f3-49cb-896f-3af644be1be3' 和 '4c1539c4-9e0f-42c4-aace-b493c96ec2e4')
Get-RsSubscription -ReportServerUri $reportServerUri_src -RsItem "/fsqa"
更改特定订阅的开始日期时间
Get-RsSubscription -ReportServerUri $reportServerUri_src -Path "/fsqa" | Where-Object {$_.SubscriptionId -eq '4c1539c4-9e0f-42c4-aace-b493c96ec2e4'} | Set-RsSubscription -StartDateTime "2/13/2019 1:20pm" -verbose
更改整个文件夹的开始日期时间
Get-RsSubscription -ReportServerUri $reportServerUri_src -Path "/fsqa" | Set-RsSubscription -StartDateTime "2/13/2019 1:20pm" -verbose
(奖励)将所有订阅从一个服务器文件夹移动到另一个(gcod050 "/fsqa" 到 gcod049 "/fsqa")
--移动订阅(From/To文件夹)
注意,2/13/19:A bug 目前正在解决这个问题。
Get-RsSubscription -ReportServerUri $reportServerUri_src -RsItem "/fsqa" | Copy-RsSubscription -ReportServerUri $reportServerUri_tgt -RsItem "/fsqa" -verbose
--创建文件夹
New-RsFolder -ReportServerUri $reportServerUri_tgt -RsFolder '/' -FolderName 'FSQA' -Description 'Reports for Food Saftey Quality Asurance department' -Verbose
--- Messages output from '-Verbose' parameter ---
VERBOSE: Establishing proxy connection to http://gcod050/ReportServer/ReportService2010.asmx...
VERBOSE: Creating folder FSQA...
VERBOSE: Folder FSQA created successfully!
--移动报告(From/To文件夹)
嗯...我不太明白 PS 模块命令将报告从服务器 A 移动到服务器 B。通过 Powershell 发布报告的命令似乎都适用于本地文件 (Link Name: Article). Here is an easy-to-use tool you can download for moving reports from ServerA to ServerB, SSRS 2008 R2 to SSRS 2016 Migration。
NOTE:
The "Content" cmdlets (based upon the documentation) appear to move files from/to a directory, instead of ServerA to ServerB
CMD:
get-command -module ReportingServicesTools *cont*
OUTPUT:
CommandType Name ModuleName
----------- ---- ----------
Function Get-RsFolderContent ReportingServicesTools
Function Out-RsFolderContent ReportingServicesTools
Function Out-RsRestFolderContent ReportingServicesTools
Function Write-RsFolderContent ReportingServicesTools
Function Write-RsRestFolderContent ReportingServicesTools
演示:截图
POSH_Get-RsSubscription -ReportServerUri $reportServerUri -Path fsqa.png
Get-RsSubscription -ReportServerUri $reportServerUri -Path "/fsqa"
POSH_get-help得到-RsSubscription.png
get-help Get-RsSubscription
POSH_Get-Help Set-RsSubscription -详细
Get-Help Set-RsSubscription -detailed
POSH_Get-Help复制-RsSubscription.png
Get-Help Copy-RsSubscription
POSH_Get-Command -模块 ReportingServicesTools.png
Get-Command -Module ReportingServicesTools
更新 2019 年 2 月 12 日星期二 16:27:33.22
我发现了 2017 年 8 月的另一篇文章,其中讨论了如何通过 PowerShell 以编程方式修改 SSRS 订阅--Warrenestes.com "Update Multiple SSRS Subscriptions"。在他的网站上,他使用 New-WebServiceProxy 开发了自己的 PoSH 函数,这对我来说看起来有点复杂。但他确实在他关于 cmdlet SET-RSSUBSCRIPTION 的文章中说过:
Edit: This is now part of the official Microsoft ReportingServicesTools PowerShell module.
This a brand new function, which was recently renamed from Update to Set-RsSubscription!!!!!.
他说了这个...
I did find a post on dba.stackexchange referencing the real [EndDate] from a column
in **dbo.Subscritions** called… wait for the descriptive name... **[MatchData]**!