Bug? in TADOConnection.SetConnectionObject



Hi,

I tentatively suggest that there may be a small problem in AdoDB and report my findings so that I can be shot down by the experts or build up a proper QC report.

A similar situation was described in this newsgroup on Feb 24, 2000 ("Connection sharing between modules") but the AdoDB code doesn't appear to have changed...

Background: I have a connection to the "current" ADO database (actually MS Access)

My program synchronises databases in one of two directions:
1) Listing the differences between "current" and "previous" versions
2) Merging into a "newer" database some private data from the "current" version

Each synchronisation creates two AdoConnections ("This" and "That")

Depending on the synch direction, one of these creates a new connection to an Access Data File (by building a ConnectionString and calling "Open") while the other just piggybacks on the existing (open) connection "aAdoConnection.ConnectionObject := aConnectionObject" and records the fact that it is piggy-backing - because it must not close this connection when it finishes the synchronisation.

When the synchronisation is finished - and this bit all works wonderfully well - I explicity nil the ConnectionObject for the piggy-backed AdoConnection so that neither a subsequent explicit call to "Close" nor an implicit call from Destroy should actually do anything when they call "DoDisconnect"...

procedure TADOConnection.DoDisconnect;
begin
if Assigned(ConnectionObject) then
begin
while InTransaction do RollbackTrans;
ConnectionObject.Close;
end;
end;

EXCEPT... despite my endeavours, the Connection is still closed in the Destroy, and this is because setting "aAdoConnection.ConnectionObject := nil" has zero effect...

procedure TADOConnection.SetConnectionObject(const Value: _Connection);
begin
CheckInActive;
if Assigned(Value) then *** !!! ***
begin
OleCheck(ConnectionPoint.UnAdvise(FConnEventsID));
FConnectionObject := Value;
OleCheck(ConnectionPoint.Advise(Self as IUnknown, FConnEventsID));
end;
end;


The previous thread suggested a fix, but it doesn't handle the "nil" situation correctly.
My extended suggestion follows...

procedure TADOConnection.SetConnectionObject(const Value: _Connection);
begin
CheckInActive;

// Unlink events *before* releasing the old connection object
if ( FConnEventsID > 0 ) then
OleCheck(ConnectionPoint.UnAdvise(FConnEventsID));

// Explicitly clear FConnEventsID so the Destructor won't call another "UnAdvise"
FConnEventsID := 0;

// Update the ConnectionObject value
FConnectionObject := Value;

// Relink events *after* assigning the new connection object (if any)
if Assigned (Value) then
OleCheck(ConnectionPoint.Advise(Self as IUnknown, FConnEventsID));
end;


Any comments?


D2006 Update 2 10.0.2558.35231

--
Paul Scott
Information Management Systems
Macclesfield, UK.
.



Relevant Pages

  • Re: Frustration and Excitement with Crystal Reports
    ... data in it to report on. ... 'you may have to fool with the right hand side to get the right connection - ... Right click on the Database Fields. ... Select "Set Datasource Location". ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Am I attacked ?
    ... found no logic) TCP ports, to various ports, and it wasn't blocked!?! ... What should I do about that belgium intrusion (report? ... "Zebedee" a écrit dans le message de ... > blocked those connection attempts:) ...
    (comp.security.firewalls)
  • Re: Virgin Media team up with SamKnows to see who is best? Virgin media come out tops!!
    ... My observation last year of the 20Mb/s line last year was that congestion in peak times regularly slowed the per connection speed to between 1-2Mb/s. ... This was a good report, I believe it was after this report that interested parties, such as VM, started funding Samknows. ... However much of my internet usage involved single thread operations such as video streaming and this meant the the VM line significantly under performed a 4Mb/s DSL line. ... So given that and comparing it to those mealy mouthed "up to" speeds ...
    (uk.telecom.broadband)
  • Jimmie quits knitting
    ... Shah, in connection with bottoms disappointed and elderly, gasps ... then report at last the question alongside the farm. ... Taysseer, have a overseas cinema. ... appreciate architectural desires to fortunately suffer. ...
    (sci.crypt)
  • Re: Wifi indicator LED - update
    ... Then I lost the connection. ... something turns wifi off and it can't be turned back one. ... No, the router is 24/7, and gets a reboot maybe 6 times/year. ... If I find any evidence to even suggest a likely explanation I'll report ...
    (Fedora)