I have a server which (rarely) dynamically creates database rows to accommodate the data model the user configures. During startup the server may have to create about a thousand rows as well as multiple inserts into existing tables.
When all this is done, it commits the transaction and sends out notifications about the new data model to anyone who might be listening. The issue is, that transaction.Commit() appears to return before the database has actually finished making the changes, so if a client makes a request to the server after it has sent out the notifications, the client may get an empty result. My assumption was that waiting for transaction.Commit() would ensure that the transaction was all done and committed.
The reason why the client gets an empty result is that when not doing DDL operations the database is using snapshot isolation, so clearly the snapshot is taken before the DDL operation has completed (but well after transaction.commit has returned)
The order of operations is:
- Start transaction
- Do thousands of operations in database (DDL)
- Commit transaction
- Send notifications about changes
- Client requests data (Snapshot isolation)
- No data (state before transaction) is returned to client.
Why does transaction.Commit() finish before the transaction has finished committing? How can I make the server wait for the transaction to be completely finished before proceeding to send out the notifications?
Edit: Clarity.