0
Assuming the following code:
/*
DROP TABLE #Teste;
CREATE TABLE #Teste(id INT);
INSERT INTO #Teste VALUES(1);
CREATE TABLE LogErros(id INT IDENTITY(1,1) PRIMARY KEY, nomeTransaction VARCHAR(100), errorMessage VARCHAR(500), horaErro DATETIME)
DROP TABLE LogErros
SELECT * FROM LogErros
*/
SET XACT_ABORT ON
DECLARE @TranName VARCHAR(20) = 'TR_Teste';
BEGIN TRANSACTION @TranName
BEGIN TRY
INSERT INTO #Teste VALUES(2);
INSERT INTO #Teste VALUES(3);
--INSERT INTO #Teste VALUES('Oi');
COMMIT TRANSACTION @TranName
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION @TranName
INSERT INTO LogErros VALUES(@TranName, CAST(ERROR_LINE() as VARCHAR) + ' - ' + ERROR_MESSAGE(), GETDATE());
END CATCH
The use of XACT_ABORT()
in such cases?
I saw in international stackoverflow that the previous function manages to deal with cases where the previous process suffers timeout
for example, problem that the TRY/CATCH
can’t treat (I may have misunderstood). Thinking about this case, then the use is valid, correct?
But I also saw people saying that XACT_ABORT()
became obsolete after the TRY/CATCH
, Is that true? So, the TRY/CATCH
can handle all mistakes on its own?
I don’t have time to go into more detail about this, but I recommend this one reading ;)
– Tuxpilgrim
Great reading, @Tuxpilgrim, if you want to earn 10 points, if no one answers the question, you can turn it into a question that I accept.
– D. Watson
If later someone doesn’t answer I’ll do it!
– Tuxpilgrim