Generic failure using sp_send_dbmail in SQL Server 2014

后端 未结 3 2084
时光说笑
时光说笑 2021-01-13 23:51

I\'m trying to use sp_send_dbmail to send the results of a query through a SQLAgent job in SQL Server 2014. I believe I have my DBMail profile set up properly

3条回答
  •  隐瞒了意图╮
    2021-01-14 00:49

    There's another reason why you might get this error; if the query has an issue.

    In our case we had (note that it's not due to a syntax error; note the missing quotes):

    DECLARE @EmailQuery varchar(max) = 'select 
                                        e.Field1,
                                        REPLACE(REPLACE(e.ExceptionReason, CHAR(13), ''), CHAR(10), '') ExceptionReason,
                                        e.UserName
                                    from dbo.tblException e'
    

    Once we corrected it as follows, it worked fine:

    DECLARE @EmailQuery varchar(max) = 'select 
                                        e.Field1,
                                        REPLACE(REPLACE(e.ExceptionReason, CHAR(13), ''''), CHAR(10), '''') ExceptionReason,
                                        e.UserName
                                    from dbo.tblException e'
    

提交回复
热议问题