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?

3
  • 1
    Where's your try/catch block?
    – Kermit
    Commented May 1, 2013 at 20:15
  • I tried to put it around sp_send_dbmail in my tests (sorry I don't have the code anymore)
    – Denis
    Commented May 1, 2013 at 20:48
  • This appears to be a duplicate of this question, which links to a relevant Connect item although there is no solution as such
    – Pondlife
    Commented May 1, 2013 at 21:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.