Daniel Magin’s Weblog

My life in the Developers World

DBXPooling and Broken Connections

Hi all,

if you use the DBXPooling ehancement in your Delphi 2007 and DBX and your connection to the server is broken, the broken connection goes back in the pool and you get back sometimes this broken connection. So i have changes some lines in the DBXPool.pas (..\program files\codegear\rad studio\5.0\source\database\src\pas\dbx\driver\). In the ReleaseConnection method of the TBXPool class i check to start a transaction and commit it. if it not works something is wrong with the connection and i give this connection not back to pooling container. The Pool is now creating a new connection for you.
Here are the small changes:

procedure TDBXPool.ReleaseConnection(Connection: TDBXConnection);
var
  MyTrans: TDBXTransaction;

begin
  try
     Mytrans:= Connection.BeginTransaction(0);
     Connection.CommitFreeAndNil(MyTrans);
     FCriticalSection.Acquire;
     try
       FAvailableConnectionArray[FAvailableConnections] := Connection;
       inc(FAvailableConnections);
     finally
       FCriticalSection.Release;
     end;
  except
  end;

  FSemaphore.Release;
end;

regards Daniel Magin

May 5, 2008 - Posted by dmagin | Embarcadero (CodeGear) stuff | | 2 Comments

2 Comments »

  1. Why did you put the transaction check code inside the critical section? inc(FAvailableConnections); has to be, but the transaction code itself might introduce an unnecessary bottelneck.

    Comment by Olaf Monien | May 5, 2008

  2. hi olaf,

    yes you are right. so i have updated the code.

    thanks and i hope to see you soon

    daniel magin

    Comment by dmagin | May 5, 2008

Leave a comment