1

I want to use SQL Server 2014 database mail. I have configured email profile and successfully send emails with fixed text body. Now I try to send query result with email bit I receive

Failed to initialize sqlcmd library with error number -2147024809

My query:

EXEC sp_send_dbmail 
@profile_name='test mail',
@recipients='mymail@mydomain.com',
@subject = 'test',
@execute_query_database = 'mydb',
@body = 'test',
@body_format = 'HTML', 
@append_query_error = 1,
@query = N'SELECT * FROM mydb..FIExchangeRates;',
@query_result_header = 0,
@attach_query_result_as_file = 1,
@query_attachment_filename = 'Test.doc',
@exclude_query_output = 0,
@query_no_truncate = 1;

What I tried to solve?

  1. Created a job with query above.
  2. Gave db access to SQLSERVERAGENT user.
  3. Set @exclude_query_output = 1
  4. Trace with SQL Profiler
  5. Google.

Here is the screenshot of problem

x

James Z
  • 12,209
  • 10
  • 24
  • 44
  • check your error logs: a quick google with your exact message gave: http://www.sqlservercentral.com/articles/SQLCMD/123681/ . It's likely a permissions problem. – Mitch Wheat Aug 14 '18 at 13:09
  • Thank you for your comment. I have follow the steps mentioned at link you shared. Still same problem. Database Mail log and SQL Profiler error logs does not help me. By the way error code is not 2147467259 but 2147024809. – Nihad ELIYEV Aug 14 '18 at 15:11
  • Query neither run in Management Studio nor in Job. – Nihad ELIYEV Aug 15 '18 at 09:35
  • Do you have rights to run sp in `msdb` database? – Serg Jan 28 '19 at 16:30

0 Answers0