Page 1 of 1

TLiteConnection.Pooling - how to use them right ?

Posted: Tue 17 Jan 2017 19:38
by Max Terentiev
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 )

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

Posted: Mon 23 Jan 2017 04:45
by Max Terentiev
I dig to the source and understand how it's works: TLiteConnections must be created with exactly same settings to make pooling works....

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

Posted: Tue 24 Jan 2017 10:48
by MaximG
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