Hi!! I've a problem with many transactions with one connection.
I explain :
1. I ´ve a. 2 DataModules: DataModule1 and DataModule2.
b. Transactions(TIBCTransaction), 3 components ( tranUpdate1, tranUpdate2, tranUpdate3)
c. TIBCQuery, 3 components
vQuery1 ( Insert data in table1, with Autocommit Property := false)
vQuery2 ( update data in table2, with Autocommit Property := false)
vQuery3( update data in table3, with Autocommit Property := false)
d.One TIBCConnection contains DBCon ( Interbase XE7).
2.I create and define:
tranUpdate1 := TIBCTransaction.Create(DBCon)
tranUpdate2:= TIBCTransaction.Create(DBCon)
tranUpdate3 := TIBCTransaction.Create(DBCon)
So 3 transactions are conected one DBCon (TIBCConnection):
tranUpdate1.DefaultConnection:= DBCon;
tranUpdate2.DefaultConnection:= DBCon;
tranUpdate3.DefaultConnection:= DBCon;
3 transactions opened/Closed at the same time
3 transactions are closed by a Commit/rollbact action.
3.Open Connection: DB.Open
4..I create and define:
vQuery1 := TIBCQuery.Create(nil);
vQuery2 := TIBCQuery.Create(nil);
vQuery3 := TIBCQuery.Create(nil);
vQuery1 .Update Transaction:= tranUpdate1;
vQuery2 .Update Transaction:= tranUpdate2;
vQuery3 .Update Transaction:= tranUpdate3;
vQuery1.Open
vQuery2.Open
vQuery3.Open
5. Start Transactions
tranUpdate1.StartTransaction
tranUpdate2.StartTransaction
tranUpdate3.StartTransaction
6. Prepare and execute vQuery1, vQuery2 and vQuery3, but if any vQuery? fail and
control Connection then
If (tranUpdate1.Active = false) or (tranUpdate2.Active = false) or
(tranUpdate3.Active = false) or ( DBCon.TransactionCount<> 3) then
tranUpdate1.Rollback
tranUpdate2.Rollback
tranUpdate3.Rollback
But If (tranUpdate1.Active= true ) or (tranUpdate2.Active = true) or
(tranUpdate3.Active= true) or DBCon.TransactionCount = 3 then
tranUpdate1.Commit
tranUpdate2.Commit
tranUpdate3.Commit
But i don´t know DBCon.Default Transactions, which transaction I choose?
DBCon.Default Transactions:= ¿? ( TranUpdate1 or TranUpdate2 or TranUpdate3?
Thanks in advance
Angélica ( Arizmendi Team)
Many transactions and One Connection
-
- Posts: 10
- Joined: Fri 13 Jul 2018 18:36
Re: Many transactions and One Connection
Hi: Is the code wrong?
I don´t know why it doesn´t work,
Thanks in advanced,
Angélica ( Arizmendi Team)
I don´t know why it doesn´t work,
Thanks in advanced,
Angélica ( Arizmendi Team)
Re: Many transactions and One Connection
To solve your task, you can use the following code:
By default the DefaultTransaction is internal connection transaction. You can set it to external transaction component. To restore internal transaction set this property to nil.
The TransactionCount property return the number of transactions currently associated with this TUniConnection component.
In your sample, TransactionCount will equal 4: three transactions of the TUniTransaction components and the internal transaction TUniConnection.DefaultTransaction.
To control transactions manually you can use the following advice:
- use for dataset a separate transaction, not a default transaction TUniConnection;
- use for data modification UpdateTransaction.
You can get more information about working with transactions when connecting to Firebird on our forum:
http://forums.devart.com/viewtopic.php?f=24&t=32757
http://forums.devart.com/viewtopic.php?f=24&t=33879
http://forums.devart.com/viewtopic.php?f=24&t=25421
http://forums.devart.com/viewtopic.php?f=28&t=25591
http://forums.devart.com/viewtopic.php?f=28&t=32310
Code: Select all
tranUpdate1.StartTransaction;
tranUpdate2.StartTransaction;
tranUpdate3.StartTransaction;
try
... <Modify data>
vQuery1.Prepare;
vQuery1.Execute;
vQuery2.Prepare;
vQuery2.Execute;
vQuery3.Prepare;
vQuery3.Execute;
tranUpdate1.Commit; <on success, commit the changes>
tranUpdate2.Commit; <on success, commit the changes>
tranUpdate3.Commit; <on success, commit the changes>
except
tranUpdate1.Rollback; <on failure, undo the changes>
tranUpdate2.Rollback; <on failure, undo the changes>
tranUpdate3.Rollback; <on failure, undo the changes>
raise; <raise the exception>
end;
The TransactionCount property return the number of transactions currently associated with this TUniConnection component.
In your sample, TransactionCount will equal 4: three transactions of the TUniTransaction components and the internal transaction TUniConnection.DefaultTransaction.
To control transactions manually you can use the following advice:
- use for dataset a separate transaction, not a default transaction TUniConnection;
- use for data modification UpdateTransaction.
You can get more information about working with transactions when connecting to Firebird on our forum:
http://forums.devart.com/viewtopic.php?f=24&t=32757
http://forums.devart.com/viewtopic.php?f=24&t=33879
http://forums.devart.com/viewtopic.php?f=24&t=25421
http://forums.devart.com/viewtopic.php?f=28&t=25591
http://forums.devart.com/viewtopic.php?f=28&t=32310
-
- Posts: 10
- Joined: Fri 13 Jul 2018 18:36
Re: Many transactions and One Connection
VictorV:
Thanks a lot !!!!!!!!!!!
Angélica ( Arizmendi Team )
Thanks a lot !!!!!!!!!!!
Angélica ( Arizmendi Team )
Re: Many transactions and One Connection
Thank you for the interest in our products.
If you have any questions during using our products, please don't hesitate to contact us - and we will try to help you solve them.
If you have any questions during using our products, please don't hesitate to contact us - and we will try to help you solve them.