Hi All,
I'm trying to trigger an email from database. But I'm receiving below error. tried all hints got from Google. Can someone assist.
Error -
Failed to initialize sqlcmd library with error number -2147467259.
What I have tried:
USE BMS_PAYMENT
DECLARE @RECIPIENTS_EMAIL VARCHAR(MAX) = 'abc@gmail.com;'
DECLARE @STARTDATE DATETIME = (DATEADD(mi, 420, DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))))
DECLARE @ENDDATE DATETIME = (DATEADD(mi, 270, DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))))
DECLARE @body VARCHAR(MAX) = null
SET @body =
'<html>
<body style=font-family:Times New Roman,Arial,sans-serif;font-size:0.9em;>
<p>Dear Leads, </p>
<p>PFA, of users daily production status as of 4.00 pm.</p>
<p>For any queries please write to <a href = mailto: Coding.Support@omegahms.com>codingSupport</a></p>
<p style=font-family:Times New Roman,Arial,sans-serif;font-size:0.9em;>This is an auto generated mail. Please do not reply to this mail.</p>
<p>Regards,</p>
<p>BMS Team</p>'
EXEC msdb.dbo.sp_send_dbmail
@profile_name= 'DBMonitor',
@recipients=@RECIPIENTS_EMAIL,
@Subject='Daily Production Status',
@body_format = 'HTML',
@body=@body,
@query = 'select client_name, FROM [PAYMENT].[dbo].[ML_Client_Master]',
--@execute_query_database = '[PAYMENT]',
@attach_query_result_as_file = 1,
@query_attachment_filename = 'Production.csv',
@query_result_header = 1,
@query_result_separator = ',',
@query_result_width = 8000,
@append_query_error = 1,
--@query_no_truncate = 0,
@query_result_no_padding = 1