I'm trying to work in some rollback procedures into a few stored procedures. I've set up the following code. However, when I set it up to fail on purpose, the rollback does not appear to be working (the USP_Write_To_Log is not firing). What am I doing wrong?
Thanks!
DECLARE @err INT
BEGIN TRANSACTION
BULK INSERT Claims_Source_Pre
FROM 'D:\EppsShare\Staging\EPPSPre1'
WITH
(
FORMATFILE = 'D:\EppsShare\lib\Eppspre.fmt'
)
SELECT @err = @@ERROR
IF @err <> 0
BEGIN
EXEC USP_Write_To_Log 'USP_Claims_Prepaid', 'JOB FAILED: Failed to Bulk Insert'
ROLLBACK TRANSACTION
END
COMMIT TRANSACTION
Thanks!
DECLARE @err INT
BEGIN TRANSACTION
BULK INSERT Claims_Source_Pre
FROM 'D:\EppsShare\Staging\EPPSPre1'
WITH
(
FORMATFILE = 'D:\EppsShare\lib\Eppspre.fmt'
)
SELECT @err = @@ERROR
IF @err <> 0
BEGIN
EXEC USP_Write_To_Log 'USP_Claims_Prepaid', 'JOB FAILED: Failed to Bulk Insert'
ROLLBACK TRANSACTION
END
COMMIT TRANSACTION