だから私はSQLストアドプロシージャを持っています:
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
SSMS でこれを実行すると、次のようなエラーが表示されます。
Msg 22051, Level 16, State 1, Line 0
Attachment file <MyFileGoesHere> is invalid.
私が理解できないのは、「sp_send_dbmail」への呼び出しの周りに TRY/CATCH を配置すると、キャッチでエラーが発生しないのはなぜですか?