Hi,
Firstly, apologies if this post has been made in the wrong group. Running SQL Server 2012. I'm attempting to add a SQL Server Agent Job which calls a stored procedure that sends a Database Mail message. The SQL Server and SQL Server Agent both run under the NT AUTHORITY\NETWORK SERVICE account. The Database Mail service has been enabled, and a public profile created. When running the stored procedure manually, I receive no errors - everything runs as expected and I do receive an email containing the expected information.
I've created the job, job step, job schedule, attached the schedule to the job, and assigned the job to server, all using T-SQL without error. I've also enabled the mail profile on the SQL Server Agent, and I know that part is working because when the job fails, I get an email notification of the failure.
I've checked the command text in the job step and parsed it within the SQL Job Step Edit window to confirm, it shows as parsing correctly. However, when I manually run the job itself, I get the following:
Execution of job failed. See the history log for details.
I check the history log and it shows:
[474] Unable to refresh Database Mail profile Database Mail Profile. (reason: ) (Not a typo, the history log shows no reason)
[260] Unable to start mail session.
[396] An idle CPU condition has not been defined - OnIdle job schedules will have no effect
The command text on the failing job step is as follows:
DECLARE @date [varchar](10) SET @date = CAST(GETDATE() AS [varchar](10)) EXEC [dbo].[GetExceptions] @company = 'MyCompany', @checkDate = @date
With regard to the date value being passed as varchar: This stored procedure is used to check for exceptions against multiple databases on this server (hence the company parameter) via dynamic SQL. I'd much prefer to use proper data typing but this is the only way I could get it to work.
Does anyone have any suggestions on anything else I could check, or insights into why this is failing? Any help is greatly appreciated!
Best Regards
Brad