Connection pooling

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
bjans
Posts: 4
Joined: Tue 25 Mar 2014 15:42

Connection pooling

Post by bjans » Fri 22 Aug 2014 09:45

I'm trying to set up connection pooling for my application but I'm not sure how to do it the right way.

My app is a web server that handles requests in threads. Eacht thread has its own connection that shoold be pooled. The DB coe looks like this:

Code: Select all

begin
  FDBCon := TMSConnection.Create(nil);
  try
    FDBCon.Server := FServer;
    FDBCon.Database := FDatabase;
    FDBCon.Username := FUser;
    FDBCon.Password := FPassword;
    FDBCon.Pooling := True;
    FDBCon.PoolingOptions.ConnectionLifetime := 60000;

    // create query and do stuff qith query / FDBCon

  finally
    FDBCon.Free;
  end;
end;
This works, but when the application terminates I get an exception with this call stack:

Code: Select all

OLEDBAccess.TOLEDBConnection.Disconnect
CRConnectionPool.TCRLocalConnectionPool.InternalFreeConnection($40FA640,False)
CRConnectionPool.TCRLocalConnectionPool.Clear
CRConnectionPool.TCRLocalConnectionPool.Destroy
System.TObject.Free
MemUtils.TDAObjectList.Notify($3D02DE0,lnDeleted)
System.Classes.TList.SetCount(0)
System.Classes.TList.Clear
CRConnectionPool.TCRConnectionPoolManager.InternalClear
CRConnectionPool.TCRConnectionPoolManager.Destroy
System.TObject.Free
MSConnectionPool.Finalization
I think the DBConnections that I freed earlier are still in the pool and destroyed again. If I don't free the FDBCon in the threads I don't get the exception on termination but then I have a memory leak for each TMSConnection.

How should I implement the lifecycle for a TMSConnection in a pooled situation?

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

Re: Connection pooling

Post by azyk » Tue 26 Aug 2014 11:48

We couldn't reproduce the problem. Please try to compose a small sample to demonstrate the problem and send it to andreyz*devart*com.

bjans
Posts: 4
Joined: Tue 25 Mar 2014 15:42

Re: Connection pooling

Post by bjans » Wed 27 Aug 2014 08:47

I emailed you a sample application. Could you reproduce the problem?

bjans
Posts: 4
Joined: Tue 25 Mar 2014 15:42

Re: Connection pooling

Post by bjans » Fri 29 Aug 2014 06:46

Hello...? Anybody there?

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

Re: Connection pooling

Post by azyk » Tue 02 Sep 2014 08:19

We received your test sample. We will investigate this behavior and inform you about the results.

bjans
Posts: 4
Joined: Tue 25 Mar 2014 15:42

Re: Connection pooling

Post by bjans » Wed 17 Sep 2014 08:32

Do you have any results already?

dehacogmbh
Posts: 3
Joined: Fri 15 Dec 2017 09:07

Re: Connection pooling

Post by dehacogmbh » Thu 07 Oct 2021 10:59

Same here. Please make us a sample how to use pooling in a delphi webbroker application.

dehacogmbh
Posts: 3
Joined: Fri 15 Dec 2017 09:07

Re: Connection pooling

Post by dehacogmbh » Fri 08 Oct 2021 07:24

OK, i get pooling work in a console app with TIdHTTPWebBrokerBridge webserver: You need to add Vcl.Forms to your project. Without this unit, pooling fails. As far as i can see pooling fails because the connection is pooled after closing the connection but is destroyed in the pool after connection is freed. Next time you create a connection, you get one from the pool who was destroyed, and you get an access violation. Add Vcl.Forms to your project and it works like expected.

Stellar
Devart Team
Posts: 496
Joined: Tue 03 Oct 2017 11:00

Re: Connection pooling

Post by Stellar » Tue 14 Dec 2021 13:55

Hi,
Thanks for your request.

Which provider are you using to connect to MS SQL Server (prAuto, prSQL, prNativeClient, prMSOLEDB, prDirect)?

Best regards,
Sergey

Post Reply