【问题标题】:Amend SSRS Subscriptions with T-SQL使用 T-SQL 修改 SSRS 订阅
【发布时间】:2019-02-11 18:28:54
【问题描述】:

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

【问题讨论】:

    标签: ssrs-2012


    【解决方案1】:

    当我遇到报告未运行的问题时,我通常使用 EXEC dbo.AddEvent 和订阅 ID 重新启动订阅。

    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
    

    【讨论】:

      【解决方案2】:

      回答你的问题……

      可以使用 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,它带有 Powershell 第 2 版。我必须将我的 Powershell 升级到第 4 版才能使用以下说明安装 RS 模块:1)MS Installing Windows PowerShell,2)How to check the PowerShell version & install a new version。要检查您的 Powershell 版本,请执行以下任一命令...$PSVersionTable.PSVersion$psversiontable,如本文所示:Determine installed PowerShell version

      我想将它们全部移动到新的日期/时间,然后再移动 他们都回来了。

      PowerShell 的目的不仅仅是查看对象,还可以修改它们。

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

      Set-RsSubscription cmdlet 的参数可让您轻松更改订阅属性StartDateTimeEndDateOwner。然后是参数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"
      

      更改特定订阅的 STARTDATETIME

      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
      

      更改整个文件夹的 STARTDATETIME

      Get-RsSubscription -ReportServerUri $reportServerUri_src -Path "/fsqa" |  Set-RsSubscription -StartDateTime "2/13/2019 1:20pm" -verbose
      

      (奖励)将所有订阅从一个服务器文件夹移动到另一个服务器文件夹(gcod050 "/fsqa" 到 gcod049 "/fsqa")

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

      注意,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!
      

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

      嗯...我不太清楚将报告从服务器-A 移动到服务器-B 的 PS 模块命令。通过 Powershell 发布报告的命令似乎都适用于本地文件 (Link Name: Article)。这是一个易于使用的工具,您可以下载用于将报告从服务器 A 移动到服务器 B,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 get-RsSubscription.png

      get-help Get-RsSubscription
      

      POSH_Get-Help Set-RsSubscription -详细

      Get-Help Set-RsSubscription -detailed
      

      POSH_Get-Help Copy-RsSubscription.png

      Get-Help Copy-RsSubscription
      

      POSH_Get-Command -Module 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]**!
      

      【讨论】:

        猜你喜欢
        • 2011-08-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-24
        • 2011-05-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多