473,387 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Insert record to SQL regardless of trigger completion code

Hello,

In my SQL table, I currently have a trigger to send email when a new
record (from MS Access 2000 form) is inserted into the table. It
works fine. The problem is sometimes when Exchange is down or any
problem with email, no email is sent out, and no record is added to
the table.

I would like to add new record when I exit my Access form, regardless
of if Exchange is down or up, or if the trigger runs successfully or
not.

Here is my trigger (simplify):
CREATE TRIGGER trig_Notify
ON dbo.Table1
FOR INSERT
AS
DECLARE @g_user VARCHAR(25)
SET NOCOUNT ON
SELECT @g_user = X.UserName FROM inserted X
EXEC master.dbo.xp_sendmail @recipients = 't***@test.com',
@message = 'test', @subject = Test Notification'

Please help,
JP
Nov 13 '05 #1
1 1502
ha*********@yahoo.com (James P.) wrote in message news:<f4*************************@posting.google.c om>...
Hello,

In my SQL table, I currently have a trigger to send email when a new
record (from MS Access 2000 form) is inserted into the table. It
works fine. The problem is sometimes when Exchange is down or any
problem with email, no email is sent out, and no record is added to
the table.

I would like to add new record when I exit my Access form, regardless
of if Exchange is down or up, or if the trigger runs successfully or
not.

Here is my trigger (simplify):
CREATE TRIGGER trig_Notify
ON dbo.Table1
FOR INSERT
AS
DECLARE @g_user VARCHAR(25)
SET NOCOUNT ON
SELECT @g_user = X.UserName FROM inserted X
EXEC master.dbo.xp_sendmail @recipients = 't***@test.com',
@message = 'test', @subject = Test Notification'

Please help,
JP


I found the answer myself: just simply add the "COMMIT TRAN" after the
AS, and before the DECLARE statement. In that way, regardless of the
outcome of the SQL statement running email, my record is still added
to SQL.

JP
Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tom Urbanowicz | last post by:
I have a trigger. Each time the triggering event fires, I want to insert some information into another 'audit-like' table (not at all related to the trigger). Some psuedo-code is below as to what...
4
by: DTB | last post by:
I am having trouble creating an INSTEAD OF trigger in SQL Server to replicate a BEFORE UPDATE trigger from ORACLE. Here is a sample of the ORACLE BEFORE UPDATE trigger: CREATE TRIGGER myTRIGGER ON...
1
by: shottarum | last post by:
I currently have 2 tables as follows: CREATE TABLE . ( mhan8 int, mhac02 varchar(5), mhmot varchar(5), mhupmj int )
3
by: Tom Urbanowicz | last post by:
I have a trigger. Each time the triggering event fires, I want to insert some information into another 'audit-like' table (not at all related to the trigger). Some psuedo-code is below as to what...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.