I have a SP, called SP_Test which includes the msdb SP sp_send_dbmail.
When I run SP_Test from the Stored Procedure folder, it works perfectly fine and ends by sending an email.
But when I run SP_Test from a Job in SQL Server Agent, I get this error when it hits the sp_send_dbmail:
Executed as user: PROD\myuserid. The EXECUTE permission was denied on the object 'sp_send_dbmail'<c/> database 'msdb'<c/> schema 'dbo'. [SQLSTATE 42000] (Error 229).
I have tried to fix it by adding my userid to Users in msdb and gave myself role membership in DatabaseMailUserRole, SQLAgentOperatorRole, SQLAgentReaderRole and SQLAgentUserRole.
The error continues. Any suggestions appreciated.
When I run SP_Test from the Stored Procedure folder, it works perfectly fine and ends by sending an email.
But when I run SP_Test from a Job in SQL Server Agent, I get this error when it hits the sp_send_dbmail:
Executed as user: PROD\myuserid. The EXECUTE permission was denied on the object 'sp_send_dbmail'<c/> database 'msdb'<c/> schema 'dbo'. [SQLSTATE 42000] (Error 229).
I have tried to fix it by adding my userid to Users in msdb and gave myself role membership in DatabaseMailUserRole, SQLAgentOperatorRole, SQLAgentReaderRole and SQLAgentUserRole.
The error continues. Any suggestions appreciated.