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

前端 未结 2 1481
感动是毒
感动是毒 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'<H1>SSRS Report Subscription Failures</H1>' +
            N'<table border="1" bgcolor="##F0F0E0" >' + 
            N'<font color = "White"> <tr><th BGCOLOR ="#008080"> ScheduleID</th><th BGCOLOR ="#008080">Name</th>' +
            N'<th BGCOLOR ="#008080">Description</th><th BGCOLOR ="#008080">DeliveryExtension</th><th BGCOLOR ="#008080">LastStatus</th>' +    N'<th BGCOLOR ="#008080">LastRunTime</th>' +      
            N'<th BGCOLOR ="#008080">Path</th></tr> </font>' +
            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'</table>' ;
    
        EXEC msdb.dbo.sp_send_dbmail @recipients='Mailid',
            @subject = 'SSRS Subscription Failures',
            @body = @tableHTML,
            @body_format = 'HTML' ;
    END
    
    0 讨论(0)
  • 2021-01-06 16:24

    (You want an email when email can't be delivered?)

    Directly within SSRS this can't be done. But you could have a SQL agent monitor the status of the subscriptions. The SQL agent can be configured to send email pretty easily. The status of the last run is stored in the subscriptions table.

    From: http://blogs.msdn.com/b/deanka/archive/2009/01/13/diagnosing-and-troubleshooting-subscriptions.aspx

    select
    'SubnDesc' = s.Description,
    'SubnOwner' = us.UserName,
    'LastStatus' = s.LastStatus,
    'LastRun' = s.LastRunTime,
    'ReportPath' = c.Path,
    'ReportModifiedBy' = uc.UserName,
    'ScheduleId' = rs.ScheduleId,
    'SubscriptionId' = s.SubscriptionID
    from ReportServer.dbo.Subscriptions s
    join ReportServer.dbo.Catalog c on c.ItemID = s.Report_OID
    join ReportServer.dbo.ReportSchedule rs on rs.SubscriptionID = s.SubscriptionID
    join ReportServer.dbo.Users uc on uc.UserID = c.ModifiedByID
    join ReportServer.dbo.Users us on us.UserID = s.OwnerId
    join msdb.dbo.sysjobs j on j.name = CONVERT(nvarchar(128),rs.ScheduleId)
    

    But none of these methods queue the email: they try, and if there is a network problem they give lose the email. You could possibly install a SMTP relay on your Reporting Services machine to get around this.

    0 讨论(0)
提交回复
热议问题