Clearing the Poolmanager

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Posts: 6
Joined: Wed 08 Jun 2016 13:45

Clearing the Poolmanager

Post by Deeem2031 » Fri 26 Aug 2016 13:06

Hello again,

we migrated from ADO to SDAC. The next step for us was to enable connection pooling from SDAC. To get rid of connections to a database we want to delete we call TMSConnectionPoolManager.Clear. In some cases we get an access violation when we close a query afterwards. The pooling causes the connection to be put back into the pool which was freed before. Following an example to replicate the issue:

Code: Select all

  con: TMSConnection;
  qry: TMSQuery;
  con := TMSConnection.Create(nil);
  con.ConnectString := 'Data Source=TEST;Initial Catalog=TEST;Authentication=Windows';
  con.Pooling := True;
  qry := TMSQuery.Create(nil);
    qry.Connection := con;
    qry.SQL.Text := 'SELECT 1';
    con.Free; // here access violation
Since TMSConnectionPoolManager.Clear isn't documented we are not sure if we use it properly or whether it is an implementation problem on your side. Any help is appreciated.

Best regards

Devart Team
Posts: 1057
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Clearing the Poolmanager

Post by azyk » Mon 29 Aug 2016 09:49

Connection Pooling in SDAC controls creation and destruction of connections to server automatically. When pooling is used, then on calling the TMSConnection.Close method, connection to the server won't be closed, and it will be put into the pool for the number of milliseconds specified in TMSConnection.PoolingOptions.ConnectionLifetime. After that period, connection will be closed and deleted from the pool, if no other instance of TMSConnection uses it.

Therefore, in the sample you have provided, call of the TMSConnectionPoolManager.Clear method is not correct for pool clearing from connections.

Post Reply