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:8727

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.

User Contributed Comments(1)
 [1] Nanette24Hampton | 2012-10-05 13:45:26

I took my first <a href="http://goodfinance-blog.com/topics/home-loans">home loans</a> when I was a teenager and this aided my relatives a lot. However, I need the short term loan as well.
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[106601]
2D Rotated Rectangles Collision Detection[79756]
Keyboard Hook[68952]
UDP[52984]
HTTP Proxy[36218]

::Top 5 Samples::
2D ColDet Rotated Rectangles[10624]
PS2 Mouse Driver[6110]
Wave Format Player[4994]
Reading FAT12[4880]
CodeGuru[4570]


All rights reserved to RageStorm © 2009