我正在尝试将数据库邮件发送给此查询“ exec sp_who2 sa”的结果。我对dbo.sp_send_dbmail的设置是正确的,但始终会出现 无法初始化错误编号为-2147467259的sqlcmd库。
DECLARE @sub VARCHAR(100);
DECLARE @qry VARCHAR(1000);
DECLARE @msg VARCHAR(250);
DECLARE @query NVARCHAR(1000);
DECLARE @query_attachment_filename NVARCHAR(520);
SELECT @sub = 'TEST XML ATTACHMENT';
SELECT @msg = 'Please refer to the attached spread sheet for the report.';
SELECT @query = 'exec sp_who2 sa';
SELECT @query_attachment_filename = 'test.csv';
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'result',
@recipients = 'thoang@yahoo.com',
@copy_recipients = 'thoang@yahoo.com',
@body = @msg,
@subject = @sub,
@query = @query,
@query_attachment_filename = @query_attachment_filename,
@attach_query_result_as_file = 1,
@query_result_header = 1,
@query_result_width = 256,
@query_result_separator = ' ',
@query_result_no_padding = 1;
无法初始化错误编号为-2147467259的sqlcmd库。