Page 1 of 1

Connection pooling

Posted: Fri 22 Aug 2014 09:45
by bjans
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?

Re: Connection pooling

Posted: Tue 26 Aug 2014 11:48
by azyk
We couldn't reproduce the problem. Please try to compose a small sample to demonstrate the problem and send it to andreyz*devart*com.

Re: Connection pooling

Posted: Wed 27 Aug 2014 08:47
by bjans
I emailed you a sample application. Could you reproduce the problem?

Re: Connection pooling

Posted: Fri 29 Aug 2014 06:46
by bjans
Hello...? Anybody there?

Re: Connection pooling

Posted: Tue 02 Sep 2014 08:19
by azyk
We received your test sample. We will investigate this behavior and inform you about the results.

Re: Connection pooling

Posted: Wed 17 Sep 2014 08:32
by bjans
Do you have any results already?

Re: Connection pooling

Posted: Thu 07 Oct 2021 10:59
by dehacogmbh
Same here. Please make us a sample how to use pooling in a delphi webbroker application.

Re: Connection pooling

Posted: Fri 08 Oct 2021 07:24
by dehacogmbh
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.

Re: Connection pooling

Posted: Tue 14 Dec 2021 13:55
by Stellar
Hi,
Thanks for your request.

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

Best regards,
Sergey