Solved

xp_sendmail error in Insert Trigger

Posted on 2004-08-26
10
422 Views
Last Modified: 2012-06-21
I am trying to use a Trigger to execute the xp_sendmail stored procedure so a notification message will be sent after a new record is inserted.  Here is the code I used to create the trigger:
CREATE TRIGGER [trgEmailGreg] ON [dbo].[tblRMR]
FOR INSERT

AS

exec xp_sendmail
@recipients = 'Brick, Greg',
@message = 'A new RMR has been submitted.  Please review and disposition as necessary',
@subject = 'New RMR submitted'

Every time I try to insert a record I get an error saying the xp_sendmail stored procedure cannot be found.
Why is this happening?
0
Comment
Question by:PsychoDazey
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 17

Accepted Solution

by:
BillAn1 earned 500 total points
ID: 11903308
try qualifying it with the dbname :

CREATE TRIGGER [trgEmailGreg] ON [dbo].[tblRMR]
FOR INSERT

AS

exec master..xp_sendmail
@recipients = 'Brick, Greg',
@message = 'A new RMR has been submitted.  Please review and disposition as necessary',
@subject = 'New RMR submitted'
0
 
LVL 6

Author Comment

by:PsychoDazey
ID: 11903532
OK, now I get :
xp_sendmail failed with mail error 0x8004011d (# 18025)
0
 
LVL 17

Expert Comment

by:BillAn1
ID: 11904116
Have you set up your mail profile correctly?
check out here for info...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_1_server_0r1w.asp
0
 
LVL 34

Expert Comment

by:arbert
ID: 11905659
This is my favorite SQL mail configuration link:

http://support.microsoft.com/default.aspx?scid=kb;en-us;263556&Product=sql2k


Also, kind of a bad idea to call sendmail from a trigger--it can be slow and even lock up (causing blocks/locks on your table).  Usually a better idea to use a queue table or a scheduled job that looks for add/change dates and email that way.

Brett
0
 

Expert Comment

by:tmprice
ID: 11905971
like stated above, sending an email by a trigger isn't recommended.  If the email fails to send, for whatever reason, the transaction is rolled back.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 6

Author Comment

by:PsychoDazey
ID: 11906834
I will keep that in mind....but if I can't get it to work it wont help anyways :-P
I have read both articles listed above and the mail profile I set up tests fine.  I just dont know why it wont run for me.
0
 

Expert Comment

by:tmprice
ID: 11907034
I used an app called NetMailBot that is simply an executable that sends email based on parameters.   Used a sp to build the parameters and then execute the program.   then scheduled the sp to run every X minutes.
0
 
LVL 34

Expert Comment

by:arbert
ID: 11907480
"If the email fails to send, for whatever reason, the transaction is rolled back."

Rolls back if you're lucky--most usually locks up and blocks the table....

if you run xp_sendmail from query analyzer, do you get the same error?  Can you open the outlook client on the SQL Server and test sending an email (use the SQLAgent Account to signon when you do it).
0
 
LVL 6

Author Comment

by:PsychoDazey
ID: 11931113
Sorry, I was out of town for a few days.  
Yes arbert, I get the same error in query analyzer.
Yes, I can send and receive e-mail from that mail box on the server.
How would I create a job that runs this code rather than a trigger?  Is it the same syntax (minus the for insert)?
0
 
LVL 6

Author Comment

by:PsychoDazey
ID: 11933612
I found out it was an issue with the way the account was configured in Exchange.
Since BillAn1's comment eliminated the original error message I was getting, I gave him the points.

Thanks all.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now