Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trasaction Stops after first error

Status
Not open for further replies.

digitallyskilled

IS-IT--Management
Sep 23, 2004
39
0
0
US
I am having a problem with the flow of a transaction.
as soon as it finds an error then the transaction stops. the next line says

SET XACT_ABORT ON
DECLARE ErrorCode INT

INSERT TABLE 1
IF @@Error <> 0
SET @ErrorCode = @@Error
PRINT '@ErrorCode'

IF @ErrorCode = 0
BEGIN
INSERT TABLE 2
IF @@Error <> 0
SET @ErrorCode = @@Error
END

IF @@Error <> 0
BEGIN
PRINT 'Rolled Back'
ROLLBACK TRANSACTION
ELSE
PRINT 'Committed'
COMMIT TRANSACTION

SET XACT_ABORT OFF
the problem is it never gets to Print '@ErrorCode' on the first table. But it does roll the transaction back which it is supposed to do. As soon as it reaches one failure it ignores everything else.

Any ideas how i can keep it going so I can log all of the errors at the end.
 
some errors are fatal and not trappable
SQL server 2005 will have much better capabilities to take care of problems like that

“I sense many useless updates in you... Useless updates lead to defragmentation... Defragmentation leads to downtime...Downtime leads to suffering..Defragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" --
 
In SQL 2000 only specific error levels can be recovered from. It depends on the error level that you are receiving when you run your code.

Denny
MCSA (2003) / MCDBA (SQL 2000)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
How can I tell what level of error I am getting, and how do I know if that error can be recovered from? Is there a list somewhere?
 
lookup severity in BOL



“I sense many useless updates in you... Useless updates lead to defragmentation... Defragmentation leads to downtime...Downtime leads to suffering..Defragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" --
 
When it gives you the error it will tell you the severity. Look up Severity in BOL and it will give you the list and what they all mean.

Denny
MCSA (2003) / MCDBA (SQL 2000)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top