Deepak Kumar
asked on
SQL server Database Mail Error-SQL Server 2008 R2
Hi there,
I am receiving the following error when i try to run the Agent Job which tries to send an email.
Executed as user: UserXXX. The EXECUTE permission was denied on the object 'sp_send_dbmail', database 'msdb', schema 'dbo'. [SQLSTATE 42000] (Error 229). The step failed.
Just for the test purpose, I have assigned the user-UserXXX to sysadmin privileges but still no luck.
I am running the job step Advanced->"Run as user -UserXXX' to execute this Job.
I have manually added the user UserXXX to the msdb database role 'DatabaseMailUserRole' also.
Have checked the sp_send_dbmail has the grant permission and the GranteeName- 'DatabaseMailUserRole'
Please let me know how to solve this issue?
thanks
Deepak
I am receiving the following error when i try to run the Agent Job which tries to send an email.
Executed as user: UserXXX. The EXECUTE permission was denied on the object 'sp_send_dbmail', database 'msdb', schema 'dbo'. [SQLSTATE 42000] (Error 229). The step failed.
Just for the test purpose, I have assigned the user-UserXXX to sysadmin privileges but still no luck.
I am running the job step Advanced->"Run as user -UserXXX' to execute this Job.
I have manually added the user UserXXX to the msdb database role 'DatabaseMailUserRole' also.
Have checked the sp_send_dbmail has the grant permission and the GranteeName- 'DatabaseMailUserRole'
Please let me know how to solve this issue?
thanks
Deepak
ASKER
Hi Vitor,
Thank you for your reply! When i ran the exec sp_configure 'Database Mail XPs'.I got the output.
name minimum maximum config_value run_value
Database Mail XPs 0 1 1 1
Please Note: Already database mail is working for other jobs which sends the DB mail.
I have configured this job to run as different User-UserXXX using Advanced option in Job steps, because of this, I am getting this error.
thanks
Deepak
Thank you for your reply! When i ran the exec sp_configure 'Database Mail XPs'.I got the output.
name minimum maximum config_value run_value
Database Mail XPs 0 1 1 1
Please Note: Already database mail is working for other jobs which sends the DB mail.
I have configured this job to run as different User-UserXXX using Advanced option in Job steps, because of this, I am getting this error.
thanks
Deepak
Already database mail is working for other jobs which sends the DB mail.What this job has different from the others? Only the user? The way it's sending emails? Other things?
ASKER
The user has been changed -"Run as user" and Job Owner "to different user which again has sysadmin privileges".
ASKER
Hi Vitor,
I have executed this command which was found in forum , after which the job was executed as the user which i gave in "Run as user"
GRANT EXECUTE ON object::sp_send_dbmail TO DatabaseMailUserRole.
but i have few questions on the internal calls by SQL server when the db mail job had happened.
EXEC @rc = msdb.dbo.sysmail_verify_pr ofile_sp
EXEC @retValue = sp_SendMailMessage @contract_name, @message_type, @message_data
EXEC @rc = sp_SendMailQueues @sendmailxml
EXEC @rc = msdb.dbo.sysmail_help_conf igure_valu e_sp @parameter_name = N'DatabaseMailExeMinimumLi feTime',
EXEC msdb.dbo.sysmail_help_conf igure_valu e_sp @parameter_name = N'ReadFromConfigurationFil e',
@parameter_value = @parameter_value OUTPUT
Few of the above mentioned queries were captured in SQL profiler where the Login Name still shows as 'SA'
I have made the job owner to other user and also the run as "different user" but still i can see the internal queries were executed as 'SA'
Can you tell if i disable the 'SA' login what would the Login Name for this internal calls as opposed to 'SA' now?
thanks
Deepak
I have executed this command which was found in forum , after which the job was executed as the user which i gave in "Run as user"
GRANT EXECUTE ON object::sp_send_dbmail TO DatabaseMailUserRole.
but i have few questions on the internal calls by SQL server when the db mail job had happened.
EXEC @rc = msdb.dbo.sysmail_verify_pr
EXEC @retValue = sp_SendMailMessage @contract_name, @message_type, @message_data
EXEC @rc = sp_SendMailQueues @sendmailxml
EXEC @rc = msdb.dbo.sysmail_help_conf
EXEC msdb.dbo.sysmail_help_conf
@parameter_value = @parameter_value OUTPUT
Few of the above mentioned queries were captured in SQL profiler where the Login Name still shows as 'SA'
I have made the job owner to other user and also the run as "different user" but still i can see the internal queries were executed as 'SA'
Can you tell if i disable the 'SA' login what would the Login Name for this internal calls as opposed to 'SA' now?
thanks
Deepak
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Vitor,
I have executed the Same job with the SA enbaled once and SA login disabled once and still found that the undocumented stored procedures related to DB mail are logged as 'SA' in Login Name.
My question on this,
1)Is this the intended behaviour of SQL server to execute these undocumented SP's under the 'SA' Login?
2)Even after the 'SA' login is disabled, why the login name shows as 'SA' for these internal SP's?
Please help me on this as I must explain it to client with brief information.
thanks
Deepak
I have executed the Same job with the SA enbaled once and SA login disabled once and still found that the undocumented stored procedures related to DB mail are logged as 'SA' in Login Name.
My question on this,
1)Is this the intended behaviour of SQL server to execute these undocumented SP's under the 'SA' Login?
2)Even after the 'SA' login is disabled, why the login name shows as 'SA' for these internal SP's?
Please help me on this as I must explain it to client with brief information.
thanks
Deepak
I don't know the answer for question 1 since I never worked with those SPs.
For question 2, SA sometimes can mean SQL Server account.
For question 2, SA sometimes can mean SQL Server account.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have given the test on my own to find out the real cause.
You can check that by running the following command:
Open in new window