Multiple transactions with Firedac?

Asked

Viewed 2,645 times

1

I would like to work with multiple simultaneous transactions on Firedac, making decisions (rollbacks and commits) different for each one. Is it possible? Currently, I work as follows:

try
  obj_TFDConnection.StartTransaction();
  ...
  obj_TFDConnection.Commit();
except
  obj_TFDConnection.Rollback();
end;

But this way I can only manage one transaction at a time.

  • 2

    Official documentation with resolution: http://docwiki.embarcadero.com/RADStudio/Berlin/en/Managing_Transactions_(Firedac)

2 answers

1

Friend the Firedac transaction is conceptually different from the DBX transaction. It turns out that both work with multi transactions; which means that in practice you can open a transaction, perform some kind of change in the bank, open another transaction make new changes and so on. The central issue is that we have a big difference between Firedac and DBX in the way it is viewed. So it directly implies how you work. Let’s see:

We take as an example two tables, and we will have to do an action, which consists of making an Insert in each table, if both run smoothly is commit and return "OK" to the main function.

In DBX we will realize that the second transaction has no relation to the first. I am if you commit on the first and rollback on the second will be at the end we will only have an insert;

Already in Firedac the same situation. If we commit on the first and rollback on the second, both transactions will be rollback; it’s like the first boss on everything.

This is a huge difference if you are thinking of migrating;

-1

When they sold the POWER of Firedac by seeing the image of being able to reconnect to the database (without losing the data) it was a miracle... But they didn’t tell the Post that we would face for those coming from DBX... It was rough, but you can handle it like this;

Transaction1 := Tfdtransaction.Create(nil); Transaction1.Connection := Tdtmdl(Dtmdl). Sqlcnctnbancodate; Transaction1.Options.Autocommit := False; Transaction1.Options.Disconnectaction := xdRollback;

Transaction2 := Tfdtransaction.Create(nil); Transaction2.Connection := Tdtmdl(Dtmdl). Sqlcnctnbancodate; Transaction2.Options.Autocommit := False; Transaction2.Options.Disconnectaction := xdRollback;

SQL1 := Tfdquery.Create(nil); SQL1.Connection := Tdtmdl(Dtmdl). Sqlcnctnbancodate; SQL1.Connection.Txoptions.Autocommit := False; SQL1.Transaction := Transaction1;

SQL2 := Tfdquery.Create(nil); SQL2.Connection := Tdtmdl(Dtmdl). Sqlcnctnbancodate; SQL2.Connection.Txoptions.Autocommit := False; SQL2.Transaction := Transaction2;

Try if Transaction1.Active = False then Transaction1.Starttransaction;

if Transaction2.Active = False then Transaction2.Starttransaction;

Transaction1.commit; Transaction2.commit; except Transaction1.rollback; Transaction2.rollback; end;

Obs. All SQL run in SQL1 will be handled in transaction1 All SQL run in SQL2, will be handled in teansaction2

I hope I helped; [] s

Browser other questions tagged

You are not signed in. Login or sign up in order to post.