Database mail with @query issue!

  • I had a problem similar to this but when I tried to include a file attachment with the email. The solution was to execute the code on the server rather than from your profile. i.e. remotely login to the server and run it from there.

  • Thanks it solve my problem

    and i want to give example

    how to use for person like me

    EXEC msdb.dbo.sp_send_dbmail

    @profile_name = 'Account',

    @recipients = 'email@domain.com',

    @query =

    'Declare @date smalldateTime

    SET @date= CAST(CAST(YEAR(GETDATE()) AS VARCHAR(4)) + ''/'' +

    CAST(MONTH(GETDATE()) AS VARCHAR(2)) + ''/01 05:00:00''

    AS smallDATETIME)

    Select Column1,Column2,

    (

    select Count(1)

    from DatabaseName.dbo.TableName1

    where Column1=DL.Column1

    and Column23=2

    and ColumnDate>= @date

    and ColumnText<>''SomeText''

    ) as CountColumn

    from DatabaseName.dbo.TableName2 as DL',

    @subject = 'Subject ',

    @attach_query_result_as_file = 1 ;

  • Hi ..check your AD acccount it may be locked.

  • Hi

    I'm using sp_send_dbmail in below given format. If i execute first two lines it's showing "Mail Queued" and executing fine then i'm able to receive mail.

    1 EXEC msdb..sp_send_dbmail

    2 @recipients = 'kr@domain.com',

    3 @subject = 'Customer Information Updated',

    4 @query = 'select * from msdb.dbo.sysjobs',

    5 @attach_query_result_as_file =0,

    6 @query_attachment_filename = 'TEST.txt'

    But when i execute whole statements at a time. Receiving the following error.

    Msg 22050, Level 16, State 1, Line 0

    Error formatting query, probably invalid parameters

    Msg 14661, Level 16, State 1, Procedure sp_send_dbmail, Line 495

    Query execution failed: Msg 15404, Level 16, State 19, Server xxxxxxxxx, Line 1

    Could not obtain information about Windows NT group/user 'domain\username', error code 0x6e.

    Please help me here. How to resolve this.

    Regards

    Arjun


    Kindest Regards,

    arj

  • This could be a permission issue on the data that you are querying for the SQL Agent service account. We had a similar issue and that's what it was. I must say this is very helpful error message.

  • bensala (4/2/2009)


    the issue is with your SQL service not able to "lookup" the AD account... Here is the cmd that DBMail runs:

    EXEC sys.xp_logininfo

    @acctname = 'Domain\User'

    If this command kicks back an error... your dbmail is going to fail. There is an option in AD to hide a user to prevent someone from being able to list all the AD users. If this option is enabled for the user in question... DBMail will fail. MS knows about this issue and as far as I know... has no intention of fixing it.

    The first thing to check if you get this error is most likely to check that the accounts SQL is running under has not been disabled. At least that is what I found to be the problem.

    Could send emails without the query, as soon as I added the query and set it to include result as file, it bombed with the error above. I did not try with result set included in the body of the email.

  • Thank you bensala.

  • I had a similar issue and the solution was just to make sure the @query_result_width had a value (250).

Viewing 8 posts - 16 through 22 (of 22 total)

You must be logged in to reply to this topic. Login to reply