I'm facing a problem on one of my stored procedure.
I run a main
procedure that call, in a transaction, a recursiveChildren
one that call herself.
Something like this :
EXEC main
{
EXEC log 'START'
BEGIN TRANSACTION
BEGIN TRY
EXEC recursiveChildren
{
IF ...
EXEC recursiveChildren
{
IF ...
EXEC recursiveChildren
{
...
}
END IF
EXEC log 'step X'
}
END IF
EXEC log 'step X'
}
IF ...
COMMIT;
ELSE
THROW error;
END TRY
BEGIN CATCH
ROLLBACK;
EXEC log 'ROLLBACK'
END CATCH
END TRANSACTION
EXEC log 'STOP'
}
As you can see, I call a logging procedure to keep track on what I'm doing, but if I need to use my THROW error
, I'm losing all information about what happened.
I read TSQL logging inside transaction that talk about log and rollback, but the table variable
is not fit for recursion as it's READONLY
when used as a parameter of a procedure.
How can I keep my log whenever I rollback or not ?