我有一个触发器,我想在表SalesClosing中的一行更新发送一封电子邮件.现在执行触发器的用户(dbuser)的权限非常有限.所以我希望触发器作为dbmailuser执行.有权发送电子邮件的用户.我测试了dbmailuser当用户登录时可以执行sp_send_dbmail.触发器触发时,我收到错误无法执行sp_send_dbmail.所以我以dbuser身份登录
,运行EXECUTE AS LOGIN =’dbmailuser’;并且能够执行sp_send_dbmail.现在为什么我不能在触发器中这样做.我使用sql server 2008.下面是触发器ddl.
,运行EXECUTE AS LOGIN =’dbmailuser’;并且能够执行sp_send_dbmail.现在为什么我不能在触发器中这样做.我使用sql server 2008.下面是触发器ddl.
alter TRIGGER SalesClosingTrigger ON SalesClosing WITH EXECUTE AS 'dbmailuser' for insert,update AS BEGIN EXEC msdb.dbo.sp_send_dbmail --@profile_name = 'Test_Email_Profile',@recipients='testemail@test.com',@body = 'This is a test for Database Mail.',@body_format = 'TEXT',@subject = 'Database Mail Test' END GO