如何在报告服务中遇到错误时设置电子邮件通知

时间:2011-10-14 16:57:55

标签: reporting-services

我为报告服务中的电子邮件传递配置了一些报告。昨晚我们遇到了一些网络故障,报告服务无法连接到数据库引擎。

是否有任何方法可以配置在无法发送订阅时发送的电子邮件通知?

我正在使用报告服务2008 R2

2 个答案:

答案 0 :(得分:5)

(如果无法发送电子邮件,您想要一封电子邮件吗?)

直接在SSRS内部无法完成。但是您可以让SQL代理监视订阅的状态。可以将SQL代理配置为非常容易地发送电子邮件。最后一次运行的状态存储在订阅表中。

来自: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)

但是这些方法都没有对电子邮件进行排队:他们会尝试,如果存在网络问题,他们会丢失电子邮件。您可以在Reporting Services计算机上安装SMTP中继来解决此问题。

答案 1 :(得分:0)

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