TLiteConnection.Pooling - how to use them right ?

Discussion of open issues, suggestions and bugs regarding LiteDAC (SQLite Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Max Terentiev
Posts: 19
Joined: Sun 05 Jun 2016 17:11

TLiteConnection.Pooling - how to use them right ?

Post by Max Terentiev » Tue 17 Jan 2017 19:38

Hi,

Please explain how to use TLiteConnection pooling ?

I have multi-threaded server where clients requests executed in threads. Usually request handler should execute sql query and return their result like this:

Code: Select all

procedure TMyServer.OnClientRequestSomeData(SomeParams:TSomeParams);
begin
LiteQuery.Sql.Add('SELECT * FROM SomeTable WHERE Filed='+SomeParams);
LiteQuery.Open;
ReturnDataSetAsJSON(LiteQuery);
end;
So, how to use connection pooling in this scenario ?

Should I create TLiteConnection and TLiteQuery every time I receive request from client:

Code: Select all

procedure TMyServer.OnClientRequestSomeData(SomeParams:TSomeParams);
var
tmpConn:TLiteConnection;
LiteQuery:TLiteQuery;
begin
tmpConn:=TLiteConnection.Create;   // How to get pooled connection ? Or I must create every time ?
tmpConn.Assign(GlobalConnection); // Copy settings from global TLiteConnection ?
LiteQuery:=TLiteQuery.Create;
LiteQuery.Connection:=tmpConn;
LiteQuery.Sql.Add('SELECT * FROM SomeTable WHERE Filed='+SomeParams);
LiteQuery.Open;
ReturnDataSetAsJSON(LiteQuery);
LiteQuery.Free;
tmpConn.Free;   // Should I free connection every time ? Or it's will be freed automatically ?
end;
Each client request (like above) executed in their own thread.

Should I free TLiteConnection every time ? Or it's will be freed by LiteDAC (PoolingOptions.ConnectionLifeTime) ? Or I should use some shared connection and they create and maintain sub-connection automatially ?

Please explain how pooling works )

Max Terentiev
Posts: 19
Joined: Sun 05 Jun 2016 17:11

Re: TLiteConnection.Pooling - how to use them right ?

Post by Max Terentiev » Mon 23 Jan 2017 04:45

I dig to the source and understand how it's works: TLiteConnections must be created with exactly same settings to make pooling works....

MaximG
Devart Team
Posts: 1030
Joined: Mon 06 Jul 2015 11:34

Re: TLiteConnection.Pooling - how to use them right ?

Post by MaximG » Tue 24 Jan 2017 10:48

You are absolutely right. Detailed information about using Connection Pooling is available by the link: https://www.devart.com/litedac/docs/?work_pooling.htm . Contact us about using LiteDAC

Post Reply