sp_send_dbmail file attachment issue

  • I have a job that sends the result of a query in the body of an email, and the attachment of a log file. Up until today it had worked fine, but today I got error message:

    Msg 22051, Level 16, State 1, Line 0

    Attachment file \\des-app2\Apps\WebProject\logs\NightlyUpdate07312.log is invalid.

    Now when I take that statement and use it in Run in windows it opens up the file just fine.   I also tried opening the file from the server logged in with the SQL server account and I could get to the file. Any idea what could cause this? 

    2nd part of the problem.  Since I know this could be a problem due to time the job might finnish I figured I would put a Try...Catch on it.  The error code for this error as reported by SQL Agent is 22051 which has severity 16.  But for some reason it is not going into my error handler.  It just throws the same error.

    I tried running it from a query window, with the same problem. 

    Any ideas and help would be greatly appreciated.

  • Are you able to send any other file.

    Are there any perculiar settings on your db server, that would help if i want to try to recreate your problem.


    Everything you can imagine is real.

  • Well looks like someone had been tinkering with security.  The server and the agent are running under two different accounts, this was supposed to have been changed 2 weeks ago, but was not done it turns out.  So I learned something new, even running as a job, sp_send_dbmail runs under the security of SQL itself and not he Agent. 

    This goes back to our change of which AD we belong to, SQL was still running under the old AD, which now needed a fully qualified server name, not just the name, to resolve.  No idea why this would suddenly have changed over the weekend but it looks like they got some DNS issues.

    Now just need to figure out why try..catch did not pick up the error.

  • i did want to point out that you should check the security settings.sometimes SQl server will throw up errors masquarading as something else but yet they are security issues


    Everything you can imagine is real.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply