Link to home
Start Free TrialLog in
Avatar of Stevie Zakhour
Stevie Zakhour

asked on

SQL JOB - Send Attachement

Hi All

I'm trying to work out why I cannot run the below script in SQL 2014 via Job, the script is below

EXEC msdb.dbo.sp_send_dbmail
	@profile_name = 'Reports',
	@recipients = 'test@test.com',
	@subject = 'Redeemed Vouchers - Attachment',
	@body = 'Hello, see the attached file Redeemed Vouchers.',
	@query = 'EXEC TunnelCosmos.dbo.Sirius_Report_Groupon', 
	@query_result_header = 1,
	@query_no_truncate = 1,
	@query_result_no_padding = 0,
	@attach_query_result_as_file = 1,
	@query_attachment_filename = 'Redeemed Vouchers.txt'

Open in new window


I can run the above script by executing it in the query window, and I'm able to receive the Redeemed Vouchers.txt, open it and view it's contents. However if I create a SQL Job and let it run I get an error, the history says:

01/29/2018 09:09:53,Report - Redeemed Vouchers,Error,2,IS-A-SQL01,Report - Redeemed Vouchers,Email Report with Attachment,,Executed as user: ISAA-SQL01\sqlserver. Failed to initialize sqlcmd library with error number -2147467259. [SQLSTATE 42000] (Error 22050).  The step failed.,00:00:00,16,22050,,,,0

Open in new window


What do you think may be causing this error?

Thanks All.
ASKER CERTIFIED SOLUTION
Avatar of Deepak Chauhan
Deepak Chauhan
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Stevie Zakhour
Stevie Zakhour

ASKER

Thanks all, makes sense!