0

So I have a sql stored proc:

CREATE PROC sp_SendConfirmedPurchasesEMail
(
    @RecID INT
)
AS
...
msdb.dbo.sp_send_dbmail
            @profile_name                   = @ProfileName,
            @recipients                     = @MailRecipients,
            @body                           = @MsgBody,
            @subject                        = @MailSubject,
            @body_format                    = @BodyFormat, 
            @importance                     = @MsgImportance, 
            @sensitivity                    = @MsgSensitivity, 
            @file_attachments               = 'Some File That Doesnt Exist',
            @query                          = @DBQuery,
            @execute_query_database         = @ExecuteQueryDatabase, 
            @attach_query_result_as_file    = @AttachQueryResultAsFile, 
            @query_attachment_filename      = @QueryAttachmentFilename,
            @query_result_header            = @QueryResultHeader,
            @query_result_width             = @QueryResultWidth,
            @query_result_separator         = @QueryResultSeparator,
            @exclude_query_output           = @ExcludeQueryOutput, 
            @append_query_error             = @AppendQueryError,
            @query_no_truncate              = @QueryNoTruncate,
            @copy_recipients                = @CC,
            @blind_copy_recipients          = @BCC,
            @reply_to                       = @ReplyTo,
            @from_address                   = @FromAddress
 END

I get an error when I run this in SSMS saying:

Msg 22051, Level 16, State 1, Line 0
Attachment file <MyFileGoesHere> is invalid.

What I can't figure out is why is it that if I put TRY/CATCH around the call to "sp_send_dbmail" I don't get the error in my catch?

Pondlife
  • 15,992
  • 6
  • 37
  • 51
Denis
  • 11,796
  • 16
  • 88
  • 150
  • 1
    Where's your `try/catch` block? – Kermit May 01 '13 at 20:15
  • I tried to put it around sp_send_dbmail in my tests (sorry I don't have the code anymore) – Denis May 01 '13 at 20:48
  • This appears to be a duplicate of [this question](http://stackoverflow.com/questions/16109138/cant-catch-errors-from-sp-send-dbmail), which links to a relevant Connect item although there is no solution as such – Pondlife May 01 '13 at 21:03

0 Answers0