digitallyskilled
IS-IT--Management
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.
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.