Set transaction_open before begin_db_transaction.

As the transaction_open flag is used to rollback transactions and the
call to begin_db_transaction may itself raise an exception, the flag
must be set upfront. Otherwise, the transaction may be left open and
the database connection will no longer be usable as the transaction is
never rolled back.

Fixes: #13595