dbTalk Databases Forums  

Sending an email from a trigger

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Sending an email from a trigger in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Travis Crow
 
Posts: n/a

Default Sending an email from a trigger - 12-17-2010 , 09:13 AM






I have a situation where I want to be able to send an email using
"execute msdb.dbo.sp_send_dbmail" when something has gone wrong with the
validation in the trigger.

Unfortunately if I raise an error and rollback the transaction, the email
does not get sent.

Is there another way to send the email?

Travis.

Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Sending an email from a trigger - 12-17-2010 , 04:34 PM






Travis Crow (noreply (AT) invalid (DOT) org) writes:
Quote:
I have a situation where I want to be able to send an email using
"execute msdb.dbo.sp_send_dbmail" when something has gone wrong with the
validation in the trigger.

Unfortunately if I raise an error and rollback the transaction, the email
does not get sent.
This is because sp_send_dbmail queues the mail on a Service Broker queue
which is transactional.

You could to things in this order:

1) Rollback
2) Send mail
3) Raiserror




--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.