locked
Failed to initialize sqlcmd library with error number -2147467259. RRS feed

  • Question

  • Hi,

    Please find the script and advice

    DECLARE @tab VARCHAR(1)
    SET @tab = CHAR(9)
    DECLARE @sub VARCHAR(100)
    DECLARE @qry VARCHAR(1000)
    DECLARE @msg VARCHAR(250)
    DECLARE @query NVARCHAR(1000)
    DECLARE @query_attachment_filename NVARCHAR(520)

    SELECT @sub = 'XXX '+ convert(VArchar,getdate()-1,103)
    SELECT @msg = 'Dear Team,

    Kindly note the Attachments  XXX

    Regards - XXXXX

    NOTE : This is an auto generated email and do not reply back'
    SELECT @query = ' SET NOCOUNT ON; Exec Reportdb.dbo.RPT_Comparison_AUTO'

    SELECT @query_attachment_filename = 'xxxx Report.xls'

    execute as login = 'sa'
    EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'REPORTS',
    @recipients = 'baskar.r@XXXXXX.com',
    @copy_recipients ='',
    @blind_copy_recipients = 'baskar.r@XXXXXX.com',
    @body = @msg,
    @subject = @sub,
    @query = @query,
    @query_attachment_filename = @query_attachment_filename,
    @attach_query_result_as_file = 1,
    @query_result_header = 1,
    @query_result_width = 32767,
    @query_result_separator = @tab,
    @query_no_truncate = 0,
    @exclude_query_output = 0,
    @query_result_no_padding =1;

    Msg 22050, Level 16, State 1, Line 0
    Failed to initialize sqlcmd library with error number -2147467259.


    baskarlakshmi

    Saturday, March 31, 2018 7:16 AM

All replies

  • Hi,

    Please see if any of these things help in your case

    1) Adding SET Quoted_identifier ON for the sql statement passed for  @query 

    2) Combination setting of below parameters

    @query_no_truncate = 1 and the  @query_result_header = 1.

    @query_no_truncate = 0 and the  @query_result_header = 0

    Thanks



    Hope this helps ! ------------------------------------------------------Please Mark This As Answer if it solved your issue. Please Vote This As Helpful if it helps to solve your issue

    Monday, April 2, 2018 10:25 AM