TLiteConnection.Pooling - how to use them right ?
Posted: 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:
So, how to use connection pooling in this scenario ?
Should I create TLiteConnection and TLiteQuery every time I receive request from client:
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 )
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;
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;
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 )