首页 > 解决方案 > 为什么我在 SQL Server 中尝试发送电子邮件时收到错误 -2147467259

问题描述

我正在尝试发送一封电子邮件,其中包含 SQL Server 中存储过程调用的结果。

declare @querytext nvarchar(100)
set @querytext = 'sp_get_SPresults @item_name = ''Name of Group'''';
EXEC msdb.dbo.sp_send_dbmail  
    @profile_name = 'My Email',  
    @recipients = 'anaddress@adomain.com',  
    @body = 'Email',  
    @subject = 'Suitable Subject' ,     
    @query = @querytext,
    @attach_query_result_as_file = 1,
@query_result_header = 1,
@query_no_truncate = 1;

但是当我运行这个时,我得到一个

消息 22050,级别 16,状态 1,第 23 行无法初始化 sqlcmd 库,错误号为 -2147467259 错误。

当我在 SQL Server 中发送测试电子邮件时,它可以正常发送。即使只是设置@querytext"select * from [Table]"不起作用。我在其他地方看到 include@query_result_header=1可以解决此类问题,但在这里似乎没有什么不同。

任何帮助,将不胜感激。

谢谢

标签: sql-serversp-send-dbmail

解决方案


最后,无论出于何种原因,我尝试仅使用以下参数:

  • @profile_name
  • @recipients
  • @身体
  • @学科
  • @body_format
  • @execute_query_database

这现在有效。感谢大家的帮助。:)


推荐阅读