插入后使用dbmail触发 [英] Trigger after insert to use dbmail

查看:70
本文介绍了插入后使用dbmail触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划在插入后创建一个触发器来发送电子邮件。

I am planning to create a trigger after insert to send an email.

最佳做法是什么?

推荐答案

使用前,必须使用数据库邮件启用数据库邮件  sp_send_dbmail的配置向导或sp_configure。

Before use, Database Mail must be enabled using the Database Mail  Configuration Wizard, or sp_configure.

和执行权限(必需)默认为 的所有成员msdb数据库中的DatabaseMailUser数据库角色。

and Execute permissions (are required) for sp_send_dbmail default to all members of the  DatabaseMailUser database role in the msdb database.

 验证MSDB数据库中的Service Broker是否已启用。

 Verify Service Broker is Enabled in the MSDB database.

--To check Service Broker is enabled or not in MSDB.
USE Master
Go
SELECT  name,is_broker_enabled
FROM    sys.databases
WHERE   database_id = DB_ID(N'msdb');
Go
-- To enable Service Broker for the msdb database:
USE master
Go
ALTER DATABASE msdb SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE;
Go

然而,当 发送邮件的用户无权使用该个人资料 对于请求,sp_send_dbmail返回错误并且不发送 消息。

However, when the  user sending the message does not have permission to use the profile  for the request, sp_send_dbmail returns an error and does not send the  message.

请仔细阅读以下文章,我们可以帮助您。

Please go through below articles , t may helps you.

https://community.spiceworks.com/topic/1409551-sql-server-trigger-sending-email-on-row-insert

https:/ /dba.stackexchange.com/questions/208304/on-insert-trigger-to-create-email


这篇关于插入后使用dbmail触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆