sp_send_dbmail 失败并带有附件 [英] sp_send_dbmail fails with attachment

查看:42
本文介绍了sp_send_dbmail 失败并带有附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要发送带有文件附件的电子邮件.附件必须来自图像类型数据字段.在查询窗口和存储过程中运行以下代码时,不会发送电子邮件.在查询窗口中,它只是说命令成功完成",但没有电子邮件.

I need to send email with file attachments. The attachment has to come from image type data field. When running the following code in both a query window and also stored procedure, no email is sent. in query window, it just says 'command(s) completed successfully', but no email.

EXEC  msdb.dbo.sp_send_dbmail @recipients = 'xx@xx.com',
    @subject = 'test',
    @execute_query_database = 'myDB',
    @body = 'test',
    @body_format = 'HTML', 
    @profile_name = 'myProfile',
    @append_query_error = 1,
    @query = 'Select docData from [myDB].[dbo].[Documents] Where id = 1',
    @query_result_header = 0,
    @attach_query_result_as_file = 1,
    @query_attachment_filename = 'Test.doc',
    @exclude_query_output = 1,
    @query_no_truncate = 1;

删除@query时发送电子邮件:

The email is send when I remove @query:

EXEC  msdb.dbo.sp_send_dbmail @recipients = 'xx@xx.com',
    @subject = 'test',
    @execute_query_database = 'myDB',
    @body = 'test',
    @body_format = 'HTML', 
    @profile_name = 'myProfile';

但我需要附件代码才能工作.任何帮助将不胜感激.

But I need the attachments code to work. Any help would be greatly appreciated.

推荐答案

评论太长.

@exclude_query_output = 0 更改为 @exclude_query_output = 1.这可能会打印有关正在发生的事情的消息(错误消息).

Change @exclude_query_output = 0 to @exclude_query_output = 1. This will likely print a message (error message) on what is going on.

在您的示例中,我能够绕过错误:

In your example, I was able to get around the error:

无法初始化 sqlcmd 库,错误号为 -2147024809.

Failed to initialize sqlcmd library with error number -2147024809.

我得到了,我希望你可能会通过将 @query_result_header = 0 更改为 @query_result_header = 1 得到.我不确定为什么缺少标题会导致它失败,但它在我的开发箱上修复了它.

that I got and I expect you'll likely get by changing @query_result_header = 0 to @query_result_header = 1. I'm not sure why the lack of headers is causing it to fail, but it fixed it on my dev box.

这篇关于sp_send_dbmail 失败并带有附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆