1

我正在尝试使用 sql server 2012 发送电子邮件。我尝试遵循几个教程但未能成功。

这是我得到的例外。

对象“sp_send_dbmail”、数据库“msdb”、模式“dbo”的执行权限被拒绝。[SQL 状态 42000]

我的代码是这样的

 EXEC msdb.dbo.sp_send_dbmail @profile_name='Test2', @recipients='test@Example.com',    
                              @subject='Test message', @body='This is the body'

我的问题是我正在使用另一个名为 Akkord 的数据库模式。但我只能sp_send_dbmail通过msdb数据库访问。我应该允许使用msdb's 的电子邮件程序,或者我应该做其他事情。

4

2 回答 2

2

The error means that the user who is trying to send Database Mail does not have the required permissions to execute sp_send_dbmail. To be able to send mail using Database mail, a user has to be a member of the ‘DatabaseMailUserRole’ role in the msdb database. Here’s how to add the user to this role

USE msdb
EXEC msdb.dbo.sp_addrolemember @rolename = 'DatabaseMailUserRole',
@membername = 'YourDomain\YourDomainUser';
GO
于 2013-06-01T12:07:08.187 回答
1

我认为您还需要在 msdb 数据库中注册您的用户。此链接可能会对您有所帮助。

于 2013-06-01T08:48:57.980 回答