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

发布于 2024-12-05 09:12:01 字数 2287 浏览 0 评论 0原文

这是我的第一个问题!因此,我希望我提供足够的信息:

我们正在尝试利用 SQL Mail Service Broker 发送大约 1000 封电子邮件。我们对此还比较陌生,但遇到了这个问题:

一些背景

我们创建了一个配置文件、一个帐户和一个配置文件帐户条目,并启用了数据库邮件。然后我们用几封电子邮件进行了测试,一切正常。然后,我们创建了一个存储过程,我们将从项目中调用该存储过程,以使用 msdb.dbo.sp_send_dbmail 对所有电子邮件进行排队。效果很好,我们可以在 msdb.dbo.sysmail_mailitems 中看到所有邮件成功排队。然后,Service Broker 就会采取行动并开始处理电子邮件。

问题

发送大约 90 个左右(绝不相同的数字)后,sql 事件日志中会多次报告错误

由于邮件原因,邮件无法发送给收件人 服务器故障。(使用帐户 42 发送邮件 (2011-09-19T17:20:09)。 异常消息:无法将邮件发送到邮件服务器。 (操作 已超时。)。使用帐户 42 发送邮件 (2011-09-19T17:21:59)。 异常消息:无法将邮件发送到邮件服务器。 (发送失败 邮件。)。 )

我参考了这个网站寻求帮助: http://www.sqlteam.com/article/how-to -troubleshoot-service-broker-problems

这让我有点困惑,我在代理运行时运行了查询分析器,一切看起来都很好。

我执行了以下命令:

    select * from sys.dm_broker_queue_monitors

它显示了状态为 NOTIFIED 的代理队列。 这种“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;

如果我运行以下命令:

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

代理再次启动,同样的情况发生。

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.

并且如果我运行以下命令:“select * from dbo.sysmail_log;”我看到了我在这篇文章顶部显示的一长串超时错误。我还发现,当所有这些错误发生时,它会关闭代理服务(我认为它被称为消息中毒),因此我需要运行 sysmail_stop_sp 并开始让它再次运行。

感谢您的帮助,我希望我提供了足够的信息。

查尔斯

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. 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. 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. This worked well, and we can see all the mail queued up successfully in msdb.dbo.sysmail_mailitems. The Service Broker then fires into action and starts processing the emails.

The Problem:

After sending roughly 90 or so (never the same number) an error is reported many times in the sql event logs

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.). )

I refered to this website for help:
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.

I executed this:


    select * from sys.dm_broker_queue_monitors

which displayed the broker queue with a state of 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:


    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:


    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;" 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.

Thanks for your help, and I hope I provided enough information.

Charles

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多像笑话 2024-12-12 09:12:01

我也遇到过类似的问题,但不幸的是从未得到答案。最后,我所能做的就是监视队列,当它崩溃时重新启动它。我使用以下存储过程来执行此操作。

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 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文