Environment: SQL SERVER2008R2
Symptom Description:
In the job, do the following: The error of this report is executed as the user NT authority\network SERVICE. Error formatting query, probably invalid parameters [SQLSTATE 42000] (Error 22050). The step failed.
But the direct execution in the SSMs client is normal to send ...
Exec
Dbo.sp_send_dbmail
@profile_name = ' mail server ',
@recipients = ' recipient ',
@subject = ' message header ',
@body = ' body ',
@query = ' select * FROM table '
Very strange, do a lot of tests to find out which part of the problem, the process is not much to repeat, directly say my solution.
The problem with the database version is finally suspected. The existing version is:
Microsoft SQL Server R2 (RTM)-10.50.1600.1 (X64)
APR 2 2010 15:48:46
Copyright (c) Microsoft Corporation
Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601:service Pack 1) (Hypervisor)
Find a test machine to hit the SP1 patch to do the test:
Microsoft SQL Server R2 (SP1)-10.50.2500.0 (X64)
June 17 2011 00:54:03
Copyright (c) Microsoft Corporation
Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601:service Pack 1) (Hypervisor)
In the job, you can finally send the message normally.
Of course there may be a better solution and no patching required. Please advise me of your knowledge.
SQL SERVER sent an error message to send SQL results via job. (Error 22050)