SQL Server

Failed to initialize sqlcmd library with error number -2147024809

We have detected following issue in production after upgrade from SQL Server 2012 SP2 to SQL Server 2014 SP1 with CU5: ‘Failed to initialize sqlcmd library with error number -2147024809“. This message is fired when we try to send email using sp_send_mail procedure with query result to be attached or in body of the email.

No one of various suggestions found on the internet helped in our environment (security, etc.) After serious investigation we found that the issue is presented only with specific values set to sp_send_mail procedure parameters. Following combinations of values is  generating the error:

As most important looks like the combination of @query_result_header and @query_no_truncated. After doing this change error disappeared. Following is working:

We are generating HTML content to email body and after changing the @query_result_header parameter from 0 to 1 all the logic is working without any change and email body is delivered as expected.

Leave a Reply

Your email address will not be published. Required fields are marked *