Datasnap and Transactions

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
smartj
Posts: 4
Joined: Wed 17 Oct 2012 03:56

Datasnap and Transactions

Post by smartj » Wed 17 Oct 2012 04:56

Hi

I am trying to get transactions working correctly with Datasnap and nested ClientDataSets (CDS).

What I have on the server is my master CDS and a detail CDS (nested). I have a master TIBCQuery and detail TIBCQuery. I have a TIBCUpdateSQL associated with the master query and a specific insert object associated with the master query.

I have a default transaction which has an DefaultCloseAction property of taCommit. I have created a 2nd transaction which has a DefaultCloseAction of taRollback. I have associated the UpdateTransaction property of my master query to this as well as the TIBCUpdateSQL.InsertObject TIBCQuery.

What is happening is when I insert a new record (for example), my master record is being commited before writing the detail record. Therefore if an exception occurs after the master insert has taken place, the record has already been written to the DB and isn't rolled back.

I think this is to do with the AutoCommit property. If it turn it off of my Insert TIBCQuery, then it doesn't write the record to the database.

I have had a look at the MIDAS demo shipped but is very old and doesn't deal with nested CDS. Am I using your components the right way?

Thanks

AndreyZ

Re: Datasnap and Transactions

Post by AndreyZ » Wed 17 Oct 2012 09:43

Hello,

If you are using explicit transactions (started by IBDAC, but not by you), note that such transactions are committed by IBDAC immediately after any change is made. If you want to make several changes and commit or roll back them all at the same time, you can use two ways:
- set the AutoCommit property of needed datasets to False and commit all changes at once manually by calling the Commit method of a transaction;
- use implicit transactions. It means that you should start a transaction (by calling the StartTransaction method of a transaction) before any changes are made, and commit all changes at once manually by calling the Commit method of a transaction as well.
Using either way, all changes will be committed or roll backed at once.

Post Reply