SP_SEND_DBMAIL occasionally failing

Have SQL Agent jobs that have literally ran for years but are now occasionally failing with the error of: "Error formatting query, probably invalid parameters".

I've checked all permissions and the query itself and they all seem to be okay. The reason I say this is because if I continually try running the job, I'll get some times that it goes through fine and sends the email attachment and others to where it fails with the error above. It leads me to believe that there is some other process going on somewhere that causes this issue, but when the job runs it doesn't know about it, fails and then gives me that generic error.

I've tried putting in an xp_stopmail, xp_startmail at different spots in the stored proc, but no luck there.

Can you guys give me some things that would cause this intermittent failure?

Thanks!
MMPTechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rich WeisslerProfessional Troublemaker^h^h^h^h^hshooterCommented:
Is there any chance you can modify your procedure to write all the parameters you are passing to sp_send_dbmail to a table before calling sp_send_dbmail?  (And if it's an automated process... put an update after the sp_send_dbmail to update a flag field to mark that line as having been successful.)  That way, when it does fail, you can confirm 100% that the parameters you think are there, really are there.

I'm going to guess that one of the parameters getting passed to the procedure isn't what it should be.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.