Failed to initialize sqlcmd library with error number 2147467259 ошибка

  • Remove From My Forums
  • Question

  • I’m trying to get SQL Server to send an email.  The test email works fine; basically DBMail works properly.  The thing is, if a human runs it, everything is fine.  If I schedule it using Sql Server Agent Job, nothing works.  I think this
    has something to do with a proxy, or some such thing. Any thoughts on what could be wrong?

    As I know, the security features are much different than those from earlier versions.

    I’m using SQL Server Developer Edition 2014.


    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

Answers

  • So it is a T-SQL jobstep from where you execute the sp_send_dbmail procedure? And if you execute exactly the same code in a query window it work fine?

    If so, check the history for the job, define and check the output file and also check the log for Database Mail. Between these three you should be able to find error message(s) that help you hunt down the root of this problem.


    Tibor Karaszi, SQL Server MVP |
    web | blog

    • Proposed as answer by

      Monday, November 3, 2014 8:45 PM

    • Marked as answer by
      Saeid Hasani
      Monday, November 3, 2014 9:23 PM

I am getting error of Failed to initialize sqlcmd library with error number -2147467259
while running below query, I tried with giving database name also but it is not working getting same error again and again. Can someone help me out in this regards.

declare @subject_line varchar (200)
  declare @sql_query varchar (8000)
  set @subject_line=(select 'Find Highest - ' + convert 
  (varchar(25),getdate(),120))
  set @sql_query=(select 'select a.productname, a.groupid, c.productstatus, 
  releasedate from #tmpa a
  join #tmpb b on a.productname = b.productname and a.prodgroupseqnr = b.maxpg
  left join [Repository_PROD].[dbo].[Product_Info] c on a.productname = 
  c.product_EDP
  order by 1')

  EXEC msdb.dbo.sp_send_dbmail
  @recipients=N'abc@gmail.com',
  @subject= @subject_line,
  @body= 'Hi ,

  Please find attached output of given query .


  Regards,
  SQLDBA_TEAM
  ',
  @execute_query_database = 'Repository_PROD',
  @query_result_header = 1,
  @query= @sql_query,
  @profile_name ='SQLDBA',
  @query_result_width=6000,
  @query_result_separator ='    ',
  @query_no_truncate = 1,
  @query_result_no_padding = 1,
  @query_attachment_filename ='Find Highest.xls',
  @attach_query_result_as_file = 1 ;

I’m trying to update some maintenance plans to make use of Ola Hallengren’s IndexOptimize,
but also mail the result of the operation using msdb.dbo.sp_send_dbmail.

Old T-SQL:

declare @indexQuery nvarchar(1000);

set @indexQuery = 'USE [MyDB];
    SELECT i.index_id, i.name, s.avg_fragmentation_in_percent 
    FROM sys.dm_db_index_physical_stats (
      DB_ID(), 
      OBJECT_ID(N''MyTable''),
      DEFAULT, DEFAULT, DEFAULT) s, sys.indexes i
    WHERE s.object_id = i.object_id
      AND s.index_id = i.index_id;';

exec msdb.dbo.sp_send_dbmail
    @profile_name = 'Local Mail Profile'
   ,@recipients = 'someone@somewhere.co.uk'
   ,@subject = 'Re-index Started'
   ,@query = @indexQuery
   ,@attach_query_result_as_file = 1
   ,@query_attachment_filename = 'Reindex BEFORE.txt'

…and this works perfectly fine.

But if I modify @indexQuery thusly:

set @indexQuery = 'IndexOptimize ''MyDB''';

…to make use of the IndexOptimize procedure, the result is:

Failed to initialize sqlcmd library with error number -2147467259.

I can’t seem to find anything related to the error number anywhere to work out what the problem is.
Can anyone please shed any light on it for me?

  • Remove From My Forums
  • Question

  • Hi

    I have a procedure that works fine from SSMS but sometimes fails when running via SQL Agent. The SP sends emails

    Here is the error message «Failed to initialize sqlcmd library with error number -2147467259»

    any ideas ?

    thanks


    <p>Javier Villegas | <a href=»http://www.twitter.com/javier_vill» target=»_blank» title=»Twitter» rel=»nofollow»> @javier_vill</a> |&nbsp;<a href=»http://sql-javier-villegas.blogspot.com/»
    rel=»nofollow»>http://sql-javier-villegas.blogspot.com/</a></p> Please click &quot;Propose As Answer&quot; if a post solves your problem or &quot;Vote As Helpful&quot; if a post has been useful to you

Answers

    • Marked as answer by

      Monday, April 6, 2015 2:11 PM

Skip to content

While sending the mail through SQL Server using DBMail, sometimes we get the error message “Failed to initialize sqlcmd library with error number -2147467259”. This is because there is an issue with the execution. The possible scenarios are given below –

1) SQLCMD is unable to execute the code because it doesn’t know in which database the code needs to be executed

2) Invalid table name

3) Invalid column names

Check the code and correct the name of the table or column for the second and third reasons.

For the first reason, use three-part name in your SELECT statement
(Eg. DBName.dbo.TableName).
Otherwise use the input parameter “@execute_query_database”
(Eg. @execute_query_database = ‘YourDBName’).

Do let me know if you are still facing the same error.


  • Faible niv carburant ошибка
  • Fahrenheit ошибка d3d error
  • Faf client ошибка java
  • Factory tool ошибка loading config file failed
  • Factorio ошибка скачивания списка модов