Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failure to execute msdb.dbo.sp_send_dbmail

Tags:

I am getting this error:

Msg 229, Level 14, State 5, Procedure sp_send_dbmail, Line 1
The EXECUTE permission was denied on the object 'sp_send_dbmail', database 'msdb', schema 'dbo'.

The relevant part of the code:

/****** Object:  StoredProcedure [dbo].[dbo.STATUSCHANGE_EMAILALERT] ******/

EXEC msdb.dbo.sp_send_dbmail
  @recipients = '[email protected]', -- Group Email
  @subject = 'Employee Status Update',
  @profile_name ='[email protected]', -- Setup the profile name group
  @body = @body,
  @body_format = 'HTML';
like image 935
No Body Avatar asked Sep 14 '12 12:09

No Body


People also ask

Could not find sp_ send_ dbmail?

Could not find stored procedure 'sp_send_dbmail' The sp_send_dbmail stored procedure is installed in the msdb database. You must either run sp_send_dbmail from the msdb database, or specify a three-part name for the stored procedure. Use Database Mail Configuration Wizard to enable and configure database mail.

What is Msdb?

The msdb database is a system database that is used by several SQL Server components such as the SQL Server Agent service. In addition to SQL Server Agent configuration and task information, replication, log shipping, and maintenance plan data are stored in the msdb database.

How do I grant permission to run a user in SQL Server?

To grant permissions to a user, database role, or application role, select Search. In Select Users or Roles, select Object Types to add or clear the users and roles you want. Select Browse to display the list of users or roles. Select the users or roles to whom permissions should be granted.


3 Answers

Found nice and easy fix that worked for me here:

If your SQL applications can’t send email using database mail (I assume you already have DBMail Account and Profile setup), there are two things to set:

  1. SQL MANAGEMENT STUDIO > MANAGEMENT > DATABASE MAIL > right click and select CONFIGURE… > select MANAGE PROFILE SECURITY > SQL MANAGEMENT
  2. put a check on PUBLIC option
  3. click on DEFAULT PROFILE and set it to YES
  4. STUDIO > DATABASES > SYSTEM DATABASES > right click on MSDB and select NEW QUERY > then enter > grant execute on sp_send_dbmail to public and click OK
like image 155
stambikk Avatar answered Oct 14 '22 15:10

stambikk


To send Database mail, users must be a user in the msdb database and a member of the DatabaseMailUserRole database role in the msdb database. To add msdb users or groups to this role use SQL Server Management Studio or execute the following statement for the user or role that needs to send Database Mail:

EXEC msdb.dbo.sp_addrolemember @rolename = 'DatabaseMailUserRole'
    ,@membername = '<user or role name>';
GO
like image 38
Saurabh R S Avatar answered Oct 14 '22 14:10

Saurabh R S


Grant execute permission on sp_send_dbmail to the user executing the stored procedure, or add them to the role msdb.DatabaseMailUser .

like image 21
Alex K. Avatar answered Oct 14 '22 15:10

Alex K.