Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 trigger to send email

Author  Topic 

silentbob
Starting Member

18 Posts

Posted - 2013-01-10 : 11:33:30
Hi

I have a trigger to send an email if a table has an insert performed on it. When i perform the insert (from a web app) the app errors and no insert is performed and no email. My code is as follows
CREATE TRIGGER triggername2
ON expression_wish_form
AFTER INSERT
AS
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'DB Mail',
@recipients = 'bob.jones@domain.com',
@body = 'data has been inserted to the table',
@subject = 'Reminder';

GO


if I just run
   EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'DB Mail',
@recipients = 'bob.jones@domain.com',
@body = 'data has been inserted to the table',
@subject = 'Reminder';


then i get the email, any ideas?

silentbob
Starting Member

18 Posts

Posted - 2013-01-10 : 11:45:23
just to add to this, if I remove the trigger then run the web app again the row is inserted correctly
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-10 : 22:57:24
why do you need to use trigger for this notification? why not wrap insert step inside a job and add notification option from job instead?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -