How to create a two phase commit with Delphi and InterBase
This week i was given a 2h webinar over Understanding Transactions with InterBase and Delphi ( a playback you can find here LINK ).
One open Question was how to create a two phase commit with IBX in Delphi.
Follow these steps and you have created your first two phase commit application:
- Create a new Delphi Project
- Place for (minimum) 2 InterBases Databases a TIBDataBase Component
- Edit the connection String from the TIBDataBase Components to connect diffrent databases
- for example
- database1 ->127.0.0.1:c:\data\employee_1.ib
- database2 ->127.0.0.1:c:\data\employee_2.ib - Place 5 Buttons with following Captions
- add database
- start transaction
- run queries
- commit transaction
- rollback tranaction - Add ONE TIBTransaction component
- Place two TIBQuery Components (you can use later also TIBDataSet for showing data in a gird or what ever)
- edit the SQL Property of each TIBQueryComponent
- update table1 set Field1=’Ernie’ where ID=1
- update table2 set Field1=’Bert’ where ID2
table1 is in this example a table in DataBase1 and
table2 is in this example a table in DataBase2 - set of IBQuery1 properties:
- DataBase -> IBDataBase1
- Transaction -> IBTransaction1 - set of IBQuery2 properties:
- DataBase -> IBDataBase2
- Transaction -> IBTransaction1 - insert this code in the button with the caption “Add DataBase”
IBTransaction1.AddDatabase(IBDatabase1);
IBTransaction1.AddDatabase(IBDatabase2); - insert this code in the button with the caption “start transaction”
IBTransaction1.StartTransaction; - insert this code in the button with the caption “run queries”
IBQuery1.ExecSQL;
IBQuery2.ExecSQL; - insert this code in the button with the caption “commit transaction”
IBTransaction1.Commit; - insert this code in the button with the caption “rollback transaction”
IBTransaction1.Rollback; - in the form event on create open both databases and also on close do not forget to close the databses
- Compile
- Run and have fun
end;
that’s all folks
regards daniel
April 25, 2008 Posted by dmagin | Embarcadero (CodeGear) stuff | | 1 Comment
Member
DelphiLive! 2009
Blogroll
-
Blog Stats
- 44,733 hits
Login
Member of
DelphiExperts Feed- DelphiExperts Power Workshop Berlin
- DelphiExperts Power Workshop Stuttgart
- ASP.NET mit Delphi Prism
- Einführung in die professionelle Softwareentwicklung unter .NET mit Delphi Prism
- Entwicklung von Webanwendungen mit der VCL für das Web/IntraWeb
- Delphi 2010 – Was ist neu? Ein Intensiv-Workshop
- DelphiExperts Day – Delphi 2010 Dortmund
- DelphiExperts Day – Delphi 2010 Hannover
- DelphiExperts Roadshow – Düsseldorf
Delphifeeds- Giving a heading light November 15, 2009
- Si è conclusa ITDevCon 2009 [ITALIAN] November 14, 2009
- OmniThreadLibrary 1.04 alpha November 13, 2009
- The Coming RAD Studio Update November 13, 2009
- ITDevCon 2009 Report November 13, 2009
- Create Collapsible Code Blocks in Delphi Code Editor using the {$REGION} directive November 13, 2009
- ITDevCon 2009 - Day 2 November 12, 2009
- Drawing on a TStatusBar's Panel Delphi control: Styling a Panel with Background Color, Font Color, Graphics November 12, 2009
- C++Builder 2010 Boost support (Update) November 12, 2009
- CreateProcess Declaration November 11, 2009
- Wringing Yet More Speed from MIDAS.DLL November 11, 2009
- ITDevCon 2009 - Day 1 November 11, 2009
- Getting Rid of Description Pane in Delphi 2010 November 10, 2009
- Call for Delphi Developers November 10, 2009
- On the Difficulty of setting the Windows 7 Desktop Wallpaper November 10, 2009
Pages
Archives
-
Archives
- November 2009 (3)
- October 2009 (3)
- August 2009 (5)
- July 2009 (9)
- June 2009 (2)
- May 2009 (10)
- April 2009 (2)
- March 2009 (4)
- February 2009 (4)
- January 2009 (3)
- October 2008 (2)
- August 2008 (1)
-
Categories
-
RSS
Entries RSS
Comments RSS

