Solved

xp_sendmail error in Insert Trigger

Posted on 2004-08-26
10
424 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Title # Comments Views Activity
Check number of row prior to displaying gridview 10 36
convert null in sql server 12 34
replace \ by - in select 4 21
Job - date manual 1 23
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

832 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