Hi all,
If multiple statements are surrounded by BEGIN and COMMIT transaction commands - are all transactions only committed once the outer COMMIT command is reached?
There are nested SQL transactions in my process which also have BEGIN and COMMIT transaction surrounds, I believe that these transactions are been committed even if the outer (final) commit is not reached.
This presents a problem when there is a very occasional crash in the software and essentially what happens is that only the first half of the whole transaction has been committed (when none of it should if there's a crash - there's a rollback in the outer command).
Is it best to name the BEGIN/COMMIT transactions so that SQL is of no doubt which commit statement has been reached or will this not make a difference in this case?
To outline the problem, the process is a stock movement and follows this structure:
BEGIN
BEGIN
MOVE STOCK OUT OF LOCATION
CREATE AUDIT OF MOVEMENT OUT
COMMIT
BEGIN
MOVE STOCK INTO NEW LOCATION
CREATE AUDIT OF MOVEMENT IN
COMMIT
COMMIT
If the vb.net software crashes part way through outer transaction, the whole lot should be rolled back (it is surrounded with a try/catch with a rollback) BUT, it seems that sometimes the first nested transactions is left as committed thus bypassing the rollback on the whole thing.
Any thoughts would be appreciated, I'm supporting somebody else's code here and short of rewriting big chunks of it to make it work how I would have done it I'm at a loss as to how this is happening!
Many thanks
If multiple statements are surrounded by BEGIN and COMMIT transaction commands - are all transactions only committed once the outer COMMIT command is reached?
There are nested SQL transactions in my process which also have BEGIN and COMMIT transaction surrounds, I believe that these transactions are been committed even if the outer (final) commit is not reached.
This presents a problem when there is a very occasional crash in the software and essentially what happens is that only the first half of the whole transaction has been committed (when none of it should if there's a crash - there's a rollback in the outer command).
Is it best to name the BEGIN/COMMIT transactions so that SQL is of no doubt which commit statement has been reached or will this not make a difference in this case?
To outline the problem, the process is a stock movement and follows this structure:
BEGIN
BEGIN
MOVE STOCK OUT OF LOCATION
CREATE AUDIT OF MOVEMENT OUT
COMMIT
BEGIN
MOVE STOCK INTO NEW LOCATION
CREATE AUDIT OF MOVEMENT IN
COMMIT
COMMIT
If the vb.net software crashes part way through outer transaction, the whole lot should be rolled back (it is surrounded with a try/catch with a rollback) BUT, it seems that sometimes the first nested transactions is left as committed thus bypassing the rollback on the whole thing.
Any thoughts would be appreciated, I'm supporting somebody else's code here and short of rewriting big chunks of it to make it work how I would have done it I'm at a loss as to how this is happening!
Many thanks