Commit transaction must be in a try-catch, there should be no executable code between commit transaction and exception, there is no begin transaction for commit transaction, there is no rollback transaction for begin transaction.
BeginTransaction();
CommitTransaction();
Try
// ...
Except
// ...
RollbackTransaction();
// ...
Raise;
EndTry;
BeginTransaction();
Try
// ...
CommitTransaction();
Except
// ...
RollbackTransaction();
// ...
Raise;
EndTry;