Home
Tutorials
Code Snippets
Code Samples
Downloads
Links

The Blog
Our Projects
About
Contact

::Add RageStorm to Favorites!::

The Blog | Our Projects | Guest Book | About | Contact

 
Tutorial - Synchronizing multiple concurrent ADO connections
Author:Vergil
Category:Delphi
Uploaded at:29-May-03
Views:9640

In some cases, it is necessary for two clients to connect simultanously to a single Microsoft Jet OLE Database via ActiveX Data Objects (ADO). Normally, any changes introduced by a client are not immediately propagated to the other because of the buffering; this leaves a problem, if the programmer wishes the changes to be synchronized.

Microsoft describes how the issue can be resolved by using a library known as Jet And Replication Objects (JRO). Delphi's convenient set of wrappers for ADO does not include JRO; it can be imported, but using Microsoft's solution requires a simple trick, as described below:

Handling the JRE library

First, you will have to import the JRO type library. In the menu, select Project->Import Type Library, and in the list, pick up "Microsoft Jet and Replication Objects (version) Library". Push "Create Unit". In the source, usually called JRO_TLB.pas, amend the following line:

uses Windows, ActiveX, ADODB_TLB, Classes, Graphics, OleServer, StdVCL, Variants;

To:

uses Windows, ActiveX, ADODB_TLB, ADODB, Classes, Graphics, OleServer, StdVCL, Variants;

This makes Delphi identify the _Connection type in the new unit as the _Connection described in the Borland libraries (i.e. ADODB_TLB._Connection and ADODB._Connection, respectively). Build the unit and register the component.

Writing

Before each group of writes to the database, begin a transaction:

var
	Connection : TADOConnection;
{...} procedure WriteToDatabase; begin {...} Connection.BeginTrans; { Write to the database } Connection.CommitTrans; {...} end;

Reading

For reading you'll need to instanciate a JetEngine object:

uses
	{...}
	ADODB,
	JRO_TLB.	{ <-- Add the unit! }

var
	JE: JetEngine;
	Connection: TADOConnection;

begin
	JE = JetEngine.Create;
	{ ... } 
end;

procedure ReadFromDatabase;
begin
	JE.RefreshCache(Connection.ConnectionObject);
	{ ... } 
end;

As you can see, a single call will suffice. As covered elsewhere, you can also use the JetEngine object for compacting the database. To do just that, it is not even necessary to alter JRO_TLB.pas.

NOTE:
Comments that will hurt anyone in any way will be deleted.
Don't ask for features, advertise or curse.
If you want to leave a message to the author use the contacts,
if you have any question in relation to your comments please use the forum.
Comments which violate any of these requests will be deleted without further
notice. Use the comment system decently.

Post your comment:
Name:
email:
Comment:
::Top 5 Tutorials::
Embedded Python[116800]
2D Rotated Rectangles Collision Detection[88710]
Keyboard Hook[77098]
UDP[65768]
HTTP Proxy[41156]

::Top 5 Samples::
2D ColDet Rotated Rectangles[11549]
PS2 Mouse Driver[6946]
Wave Format Player[5780]
Reading FAT12[5607]
CodeGuru[5346]


All rights reserved to RageStorm © 2009