Solved

xp_sendmail error in Insert Trigger

Posted on 2004-08-26
10
425 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

839 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