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 2005 Forums
 Transact-SQL (2005)
 How to send email within trigger ?

Author  Topic 

hdv212
Posting Yak Master

140 Posts

Posted - 2010-10-11 : 15:29:42
Hi
i have configured my sql server 2008 database mail. it works fine but when i use sp_send_dbmail which exists in msdb database, i got the error which i can not use statement in trigger :

a USE database statement is not allowed in a procedure, function or trigger.

can anybody have a solution ?
thanks in advance

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-10-11 : 15:34:29
It is probably not (almost definitely not) a good idea to send email from a trigger.

Probably a better idea would be to insert info about an email to be sent into a table, and have a scheduled job to axtually send the email.







CODO ERGO SUM
Go to Top of Page

hdv212
Posting Yak Master

140 Posts

Posted - 2010-10-11 : 16:02:55
Hi
i've solved my problem.
i can use this proc without switching to msdb database :

msdb..sp_send_dbmail -- works fine

instead of :

use msdb
exec sp_send_dbmail

regards
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-11 : 16:16:39
Be sure that you never have hundreds or thousands of insert/updates at a time in your triggered table...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-10-11 : 16:21:38
no, no, sending an email from a trigger is a GREAT idea!

Do you work at a Nuclear power plant?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx





Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-10-11 : 17:25:18
quote:
Originally posted by X002548
no, no, sending an email from a trigger is a GREAT idea!...


Trying to pump up the consulting dollars?




CODO ERGO SUM
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-10-12 : 12:14:47
not a bad idea....

I was just wondering if the Iranian brain trust uses the same logic to build their nuclear capability



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx





Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-12 : 12:43:41
hdv212, please excuse the unkindness of his behavior...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-10-12 : 12:52:28
quote:
Originally posted by webfred

hdv212, please excuse the unkindness of his behavior...


No, you're never too old to Yak'n'Roll if you're too young to die.



...and see...I was hoping to move back to the fatherland...

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx





Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-10-12 : 13:09:13
quote:
Originally posted by X002548

not a bad idea....

I was just wondering if the Iranian brain trust uses the same logic to build their nuclear capability



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx






Iranians are smart enough to fool people around by creating a Nuclear "Virus" .

PBUH

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-10-12 : 15:46:18
I don't doubt that to be 100% true....all the more reason to be vigilant



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx





Go to Top of Page
   

- Advertisement -