Click here to Skip to main content
15,878,430 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 9-Apr-23 22:27pm

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900