error fix: The EXECUTE permission was denied on the object sp_send_dbmail, database ‘msdb’

Today I am in a mood to fix the error 😉

After reading my article at http://www.sqlhub.com/2009/04/email-from-insert-trigger-with.html one of my team members has tried to send an email from our production server and faced the error:

The EXECUTE permission was denied on the object ‘sp_send_dbmail’, database ‘msdb’

He comes to me for the solution as I am his handy reference than why he should even go to google J

Anyway, the main cause of this error is either your user does not exist in msdb database or it is not a member of DatabaseMailUserRole. How can we fix this?

If you have user exist in msdb database than simply run following script.

EXEC msdb.dbo.sp_addrolemember @rolename = ‘DatabaseMailUserRole’, @membername = ‘ritesh’

If your user doesn’t exist in msdb database than first add user to msdb and then try to execute above command like:

use msdb CREATE User[ritesh] FOR LOGIN [ritesh];

EXEC msdb.dbo.sp_addrolemember @rolename = ‘DatabaseMailUserRole’, @membername = ‘ritesh’

Hope this helps!!!!

Reference: Ritesh Shah

http://www.sqlhub.com
Note: Microsoft Books online is a default reference of all articles but examples and explanations prepared by Ritesh Shah, founder of
http://www.SQLHub.com

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: