简体   繁体   English

超时错误 - 通过SQL Mail发送邮件 - Service Broker队列

[英]Timeout Error - Sending mail through SQL Mail - Service Broker Queue

This is my first question! 这是我的第一个问题! So I hope I provide enough information: 所以我希望我提供足够的信息:

We are attempting to send around 1000 emails by taking advantage of the SQL Mail Service Broker. 我们正在尝试利用SQL Mail Service Broker发送大约1000封电子邮件。 We are relatively new to this, but have hit a wall with this problem: 我们对此比较陌生,但是遇到了这个问题:

Some Background: 一些背景:

We created a Profile, an Account and a ProfileAccount entries, and enable database mail. 我们创建了一个配置文件,一个帐户和一个ProfileAccount条目,并启用了数据库邮件。 We then tested with a few emails and all worked fine. 然后我们用几封电子邮件进行测试,一切正常。 We then created a store procedure that we would call from our project to QUEUE all the emails using msdb.dbo.sp_send_dbmail. 然后,我们创建了一个存储过程,我们将使用msdb.dbo.sp_send_dbmail从我们的项目调用所有电子邮件。 This worked well, and we can see all the mail queued up successfully in msdb.dbo.sysmail_mailitems. 这很好用,我们可以在msdb.dbo.sysmail_mailitems中看到所有邮件排队成功。 The Service Broker then fires into action and starts processing the emails. 然后,Service Broker将启动并开始处理电子邮件。

The Problem: 问题:

After sending roughly 90 or so (never the same number) an error is reported many times in the sql event logs 发送大约90个左右(从不相同的数字)后,在sql事件日志中多次报告错误

The mail could not be sent to the recipients because of the mail server failure.(Sending Mail using Account 42 (2011-09-19T17:20:09). Exception Message: Cannot send mails to mail server. (The operation has timed out.). Sending Mail using Account 42 (2011-09-19T17:21:59). Exception Message: Cannot send mails to mail server. (Failure sending mail.). ) 由于邮件服务器故障,邮件无法发送给收件人。(使用帐户42发送邮件(2011-09-19T17:20:09)。例外消息:无法向邮件服务器发送邮件。(操作已超时) 。)。使用帐户42发送邮件(2011-09-19T17:21:59)。异常消息:无法向邮件服务器发送邮件。(发送邮件失败。)。)

I refered to this website for help: http://www.sqlteam.com/article/how-to-troubleshoot-service-broker-problems 我在这个网站上寻求帮助: http//www.sqlteam.com/article/how-to-troubleshoot-service-broker-problems

Which made me a little confused, I have run Query Profiler while the Broker is running and all seems fine. 这让我有点困惑,我在Broker运行时运行了Query Profiler,一切似乎都很好。

I executed this: 我执行了这个:

select * from sys.dm_broker_queue_monitors

which displayed the broker queue with a state of NOTIFIED. 它显示了状态为NOTIFIED的代理队列。 This 'NOTIFIED' state seem to imply that the activation sp wasn't working, but the logs don't indicate this, and I checked all the following which didn't give me any clue: 这个'NOTIFIED'状态似乎意味着激活sp不起作用,但是日志没有表明这一点,我检查了以下所有没有给我任何线索的内容:

select * from sys.transmission_queue;
    select * from sys.conversation_endpoints;
    select * from sys.dm_broker_activated_tasks;
    select * from sys.dm_broker_connections;

If I run the following commands: 如果我运行以下命令:

EXEC msdb.dbo.sysmail_stop_sp;
    EXEC msdb.dbo.sysmail_start_sp;

the broker starts up again, and the same thing happens. 经纪人再次启动,同样的事情发生了。

The windows event log seemed to show the most helpful message, but I'm unsure how to solve it: Windows事件日志似乎显示了最有用的消息,但我不确定如何解决它:

Event Type: Error
    Event Source:   DatabaseMail
    Event Category: None
    Event ID:   0
    Date:       9/19/2011
    Time:       5:18:44 PM
    User:       N/A
    Computer:   _____
    Description:
    There was an error on the connection. Reason: Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached.
    Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached.

And together with that the if I run this: "select * from dbo.sysmail_log;" 如果我运行这个:“select * from dbo.sysmail_log;” I see long list of the timeout errors I showed at the top of this post. 我在这篇文章的顶部看到了很长的超时错误列表。 I have also discovered that when all these errors occur it closes down the Broker Service (Message Poisoning I think it's called) so therefore I need to run the sysmail_stop_sp and start to get it going again. 我还发现,当所有这些错误发生时,它会关闭Broker Service(消息中毒,我认为它被称为),因此我需要运行sysmail_stop_sp并开始重新启动它。

Thanks for your help, and I hope I provided enough information. 感谢您的帮助,我希望我提供了足够的信息。

Charles 查尔斯

I have had a similar problem, but unfortunately never got an answer. 我有类似的问题,但遗憾的是从来没有得到答案。 In the end, all that I could do was to monitor the QUEUE and when it has crashed just restart it. 最后,我所能做的就是监视队列,并在崩溃时重新启动它。 I used the following stored procedure to do this. 我使用以下存储过程来执行此操作。

DECLARE @state nvarchar(50),
        @length int,
        @last_activated_time datetime
CREATE TABLE #MailStatusTempTable
(
[queue_type] nvarchar(max),
[length] int,
[state] nvarchar(max),
[last_empty_rowset_time] datetime,
[last_activated_time] datetime
)
INSERT INTO #MailStatusTempTable EXEC msdb.dbo.sysmail_help_queue_sp @queue_type = 'mail'
SELECT TOP 1 @state = [State],@length=[length],@last_activated_time = [last_activated_time] FROM #MailStatusTempTable
DROP TABLE #MailStatusTempTable
IF (@length>0)
BEGIN
    IF (@state <> 'RECEIVES_OCCURRING')
    BEGIN
        IF (DATEDIFF(minute,@last_activated_time,GETDATE())>5) --ensuring 5 minutes has passed since last activity (your timeout might be different)
        BEGIN
            EXEC msdb.dbo.sysmail_stop_sp
            EXEC msdb.dbo.sysmail_start_sp
        END
    END
END

I hope this is of some help to you. 我希望这对你有所帮助。 If so, please remember to mark this as the answer! 如果是这样,请记住将此标记为答案!

Kind regards, Willem 亲切的问候,威廉

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM