Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 为什么sp_send_dbmail的错误22051没有被CATCH块捕获?_Sql_Sql Server_Sql Server 2008_Sql Server 2008 R2 - Fatal编程技术网

Sql 为什么sp_send_dbmail的错误22051没有被CATCH块捕获?

Sql 为什么sp_send_dbmail的错误22051没有被CATCH块捕获?,sql,sql-server,sql-server-2008,sql-server-2008-r2,Sql,Sql Server,Sql Server 2008,Sql Server 2008 R2,因此,我有一个sql存储过程: CREATE PROC sp_SendConfirmedPurchasesEMail ( @RecID INT ) AS ... msdb.dbo.sp_send_dbmail @profile_name = @ProfileName, @recipients = @MailRecipients, @body

因此,我有一个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.
Msg 22051,第16级,状态1,第0行
附件文件无效。

我不明白的是,为什么如果我在调用“sp_send_dbmail”时加上TRY/CATCH,我的CATCH中就没有错误?

你的
TRY/CATCH
块在哪里?我在测试中试着在sp_send_dbmail周围加上TRY/CATCH(抱歉,我没有代码了),这似乎是,虽然没有解决方案,但它链接到相关的连接项