使用T-SQL修改SSRS订阅

时间:2019-02-11 18:28:55

标签: ssrs-2012

可以使用T-SQL修改现有的SSRS订阅吗?我有一种情况,由于服务器错误,许多订阅发送失败。我想将它们全部移到新的日期/时间,然后再将它们全部移回。

2 个答案:

答案 0 :(得分:0)

当我对报告无法运行有疑问时,通常使用具有订阅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

答案 1 :(得分:0)

要回答您的问题...

  

可以使用T-SQL修改现有的SSRS订阅吗?

我不确定是否可以使用TSQL更改订阅。我已经使用SQL提取了订阅...请参阅我通过SQL查询发布的答案:is there a way to query future SSRS subscription schedules?

最近我一直在与 PowerShell 一起玩管理自动化脚本。您可以为PowerShell from Microsoft on Github安装 ReportingServicesTools module 。我建议您尝试学习。在我看来,它看起来很酷,到目前为止,在我的测试中,它似乎具有一些有前途的功能。

注意:我有Windows 7,该Windows 7随附Powershell版本2。我必须按照以下说明将Powershell升级到版本4才能安装RS模块:1)MS Installing Windows PowerShell,2){{3 }}。要检查您的Powershell版本,请执行以下任一命令... $PSVersionTable.PSVersion$psversiontable,如这篇文章:How to check the PowerShell version & install a new version

  

我想将所有这些移动到新的日期/时间,然后再移动   他们又回来了。

PowerShell的目的不仅在于查看对象,还可以对其进行修改。

RSTools posh模块具有很多相关的cmdlet,包括:Get-RsSubscriptonSet-RsSubscriptonCopy-RsSubscriptonExport-RsSubscriptonImport-RsSubscriptonNew-RsSubscriptonRemove-RsSubscripton。下面,我使用 GET SET 在单个文件夹上演示了服务器上的HelpSubscription Properties

Set-RsSubscription cmdlet具有一些参数,可让您轻松更改订阅属性 StartDateTime EndDate 所有者 >。然后是参数 SubProperties ,目前还不确定这是什么。


演示:Powershell代码

声明变量

$reportServerUri_src = "http://gcod049/ReportServer"
$reportServerUri_tgt = "http://gcod050/ReportServer"

查找订阅(一个文件夹返回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”)

-移动订阅(从/到文件夹)

注意,19/2/13:Determine installed PowerShell version正在为此制定。

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!

-移动报告(从/到文件夹)

好吧...我还不太清楚PS模块将报告从服务器A移到服务器B的命令。通过Powershell来发布报告的命令似乎都可用于本地文件(A bug)。您可以下载以下易于使用的工具,将报告从ServerA移至ServerB Link Name: Article

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"

SSRS 2008 R2 to SSRS 2016 Migration

POSH_get-help get-RsSubscription.png

get-help Get-RsSubscription

enter image description here

POSH_Get-Help Set-RsSubscription-

Get-Help Set-RsSubscription -detailed

enter image description here

POSH_Get-Help Copy-RsSubscription.png

Get-Help Copy-RsSubscription

enter image description here

POSH_Get-Command -Module ReportingServicesTools.png

Get-Command -Module ReportingServicesTools

enter image description here


UPDATE Tue 02/12/2019 16:27:33.22

我从2017年8月发现了另一篇文章,该文章讨论如何也通过PowerShell-enter image description here以编程方式修改 SSRS订阅。在他的网站上,他使用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]**!