I'm having a very strange problem related to Database Mail. I wonder if anyone can help me.
I have a SQL Server 2008 database that supports our help desk. Users create trouble tickets, which send out various emails.
To send an email, my app inserts a record into a ticket email queue table. The table contains a createdate field autopopulated with getdate(),
and a senddate field that's initially null. Meanwhile I have a SQL job that runs once a minute, its job being to execute a stored procedure. The SP queries for all queue records having a null send date then loops thru the result set, sending each email in
turn. Our helpdesk is pretty busy, so typically multiple records will be inserted into the queue in a minute. Normally, you will see that each went out within a minute or two of being put in the queue.
This morning, however, the email job history suddenly began reporting that the job failed. The reason given was that I needed to specify
@recipients or @copy_recipents or @blind_copy_recipients. My SP specifies @recipients.
Then I noticed that even tho the job was failing, some emails were going out. Then I noticed that the time between the email queue record's
createdate and senddate was growing. The difference grew from the usual 1-2 minutes to, at this moment, three and a half hours. I could see too from the senddate field that exactly 1 email is being sent per minute. So I'm thinking that the SP starts working
thru its result set, sends the first email OK, then dies, causing the job to report failure.
I have made no changes to the SP, job, or anything else in ages. I have no idea how it happened or how to fix it. Restarting SQL Server did
not help.
Can anyone shed some light?
-------------------------------------------
UPDATE: The lag between createdate and senddate continued to grow overnight till it was about 9 hours. We rebooted the server this morning, but again, no change.
I noticed that if I manually execute the SP, it gives me a bunch of errors but actually sends out all the queued emails. The lag time between createdate and senddate returns to the 1-2 minute range, but grows again every few minutes. As long as I devote myself to manually running the job 24/7, everything will be great!
Here is the message I get when I manually run the SP:
Msg 14624, Level 16, State 1, Procedure sp_send_dbmail, Line 260
At least one of the following parameters must be specified. "@recipients, @copy_recipients, @blind_copy_recipients".
Msg 220, Level 16, State 2, Procedure SendEmail, Line 52
Arithmetic overflow error for data type tinyint, value = 256.
The statement has been terminated.
I created a new job and SP with the same settings thinking something may have got corrupted, but I get the same problem. I can't think of anything else to try.
UPDATE: Just came across the answer on another forum. The problem was one or more queued emails with a blank send-to address!