Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 30th, 2003, 01:10 PM
Registered User
 
Join Date: Oct 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I Avoid a ROLLBACK when...

I am using SQL Mail to send emails to several users when a new Customer Complaint record is INSERTed into a SQL Server 2000 table.

CURRENT CODE:

create trigger tr_NewCustServiceInquiry on table1 for insert as

   declare @vmessage varchar(500)
   declare @vsubject varchar(100)

   select @vmessage = 'Customer Service Quality Alert ' + char(13) + char(13) +
                      'Inquiry Number: ' + s.fcInqNo + char(13) +
                      'Customer Number: ' + s.fcCustNo + char(13) +
                      'Customer: ' + s.fcCustomer + char(13) +
                      'Part Number: ' + s.fcPartno + ' Rev: ' + s.fcPartRev + char(13) +
                      'Quantity: ' + CAST(s.fnqty AS varchar(20)) + CHAR(13) +
                      'Sales Order # ' + s.fcSono + char(13) +
                      'Problem Category: ' + p.fcpoptext,
          @vsubject = 'Quality Alert - Customer Service - ' + x.fcpoptext
   from inserted s INNER JOIN
        cspopup p ON p.fcpopkey = 'SYCSLM.FCCATEGORY' AND s.fccategory = p.fcpopval INNER JOIN
        cspopup x ON x.fcpopkey = 'SYCSLM.FCSEVERITY' AND s.fcseverity = x.fcpopval

   exec master..xp_startmail

   exec master..xp_sendmail
          @recipients = '[email protected];[email protected]',
          @blind_copy_recipients = '[email protected]',
          @subject = @vsubject,
      @message = @vmessage

   exec master..xp_stopmail

The INSERT email Trigger works great and everything runs well - normally.

But, if the Exchange Server is down or it has some other glitch that prevents the email Trigger from running properly, an error is raised in the Trigger and the entire transaction is ROLLedBACK - including the INSERTED record.

I want the Trigger to fail without a ROLLBACK of the INSERT.
I read about XACT_ABORT and I am wondering if this will work...

NEW CODE:

create trigger tr_NewCustServiceInquiry on table1 for insert as

   declare @vmessage varchar(500)
   declare @vsubject varchar(100)

set xact_abort off
go

begin transaction
   select @vmessage = 'Customer Service Quality Alert ' + char(13) + char(13) +
                      'Inquiry Number: ' + s.fcInqNo + char(13) +
                      'Customer Number: ' + s.fcCustNo + char(13) +
                      'Customer: ' + s.fcCustomer + char(13) +
                      'Part Number: ' + s.fcPartno + ' Rev: ' + s.fcPartRev + char(13) +
                      'Quantity: ' + CAST(s.fnqty AS varchar(20)) + CHAR(13) +
                      'Sales Order # ' + s.fcSono + char(13) +
                      'Problem Category: ' + p.fcpoptext,
          @vsubject = 'Quality Alert - Customer Service - ' + x.fcpoptext
   from inserted s INNER JOIN
        cspopup p ON p.fcpopkey = 'SYCSLM.FCCATEGORY' AND s.fccategory = p.fcpopval INNER JOIN
        cspopup x ON x.fcpopkey = 'SYCSLM.FCSEVERITY' AND s.fcseverity = x.fcpopval

   exec master..xp_startmail

   exec master..xp_sendmail
          @recipients = '[email protected];[email protected]',
          @blind_copy_recipients = '[email protected]',
          @subject = @vsubject,
      @message = @vmessage

   exec master..xp_stopmail

commit transaction
go
set xact_abort on
go
return

Will this work? Any ideas?
 
Old October 31st, 2003, 01:07 AM
Registered User
 
Join Date: Oct 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't think it'll work. As you know, the trigger and statement that fires it are treated as a SINGLE transaction. Trigger fails - the whole transaction fails.
I would suggest this:
create trigger mytrigger on table1
for insert
as
exec MyStoredProcedure

and have stored procedure to send your notification.
I hope that will work. Good luck.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Rollback in trigger??? (explicit/autocommit) edvin SQL Server 2005 2 April 20th, 2008 05:28 PM
Rollback of Delete gaurav_jain2403 SQL Server 2000 2 August 3rd, 2006 01:32 AM
Commit & Rollback in ASP software_developer_kk Classic ASP Basics 1 June 27th, 2005 12:13 AM
SQL trigger, rollback , update, limits brucenx SQL Server 2000 1 December 17th, 2004 07:05 AM
IS ROLLBACK MANDATORY AFTER A TIMEOUT FAILURE ? antocaro SQL Server 2000 0 March 10th, 2004 04:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.