SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 trigger to send email
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

silentbob
Starting Member

18 Posts

Posted - 01/10/2013 :  11:33:30  Show Profile  Reply with Quote
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 - 01/10/2013 :  11:45:23  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 01/10/2013 :  22:57:24  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000