How can I set up email notification when an error is encountered in reporting services

前端 未结 2 1479
感动是毒
感动是毒 2021-01-06 15:31

I have some reports that are configured for email delivery in reporting services. Last night we experienced some network outtages and reporting services was unable to connec

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-06 16:08

    Below the script will send notification too..
    
    
    --Below script can be used to send the Notification everyday morning to your email id. 
    
    DECLARE @tableHTML  NVARCHAR(MAX) ;
    DECLARE @COUNT INT
    DECLARE @FileCreationDate varchar(20)
    
    SET @COUNT = (SELECT count(*)
    FROM ReportServer.dbo.Subscriptions s
    WHERE (s.LastStatus LIKE 'Failure%' OR s.LastStatus LIKE 'Error%')
    AND s.LastRunTime > DATEADD(D, -1, GETDATE()))
    
    IF @COUNT >0 
    BEGIN
    
        SET @tableHTML =
            N'

    SSRS Report Subscription Failures

    ' + N'' + N' ' + N'' + N'' + N'' + CAST ( ( select TD = sc.ScheduleID , '', TD = c.Name , '', TD = sb.[Description] , '', TD = sb.DeliveryExtension , '', TD = sb.LastStatus , '', TD = sb.LastRunTime , '', TD = c.Path FROM ReportServer.dbo.ReportSchedule rs INNER JOIN ReportServer.dbo.Schedule sc ON rs.ScheduleID = sc.ScheduleID INNER JOIN ReportServer.dbo.Subscriptions sb ON rs.SubscriptionID = sb.SubscriptionID INNER JOIN ReportServer.dbo.[Catalog] c ON rs.ReportID = c.ItemID AND sb.Report_OID = c.ItemID WHERE (sb.LastStatus LIKE 'Failure%' OR sb.LastStatus LIKE 'Error%') AND sb.LastRunTime > DATEADD(D, -1, GETDATE()) FOR XML PATH('tr'), TYPE ) AS NVARCHAR(MAX) ) + N'
    ScheduleIDNameDescriptionDeliveryExtensionLastStatusLastRunTimePath
    ' ; EXEC msdb.dbo.sp_send_dbmail @recipients='Mailid', @subject = 'SSRS Subscription Failures', @body = @tableHTML, @body_format = 'HTML' ; END

提交回复
热议问题