Stuart Clennett 15 Posted 19 hours ago Hello all, I am returning to MARS after some years away. I noticed that the new template application has a ServerConnectionPool data module. Has anyone implemented connection pooling with a single, central datamodule and FDConnection, with a separate TDataModule for handling requests? If so, could someone give me a heads up on the best ways to set up the initial TFDConnection component on the connection-pool datamodule and how to connect this to my queries in the request handling datamodule? Thanks Stuart Share this post Link to post
mvanrijnen 125 Posted 7 hours ago (edited) You (as far as i know), need always to create (request for) a new FDConnection with each request, each request runs as it's own thread. At what "ServerConnectionPool data module" you are referring to ? (can not see somehting like this in the template folder? I have examples of how to use the FDConnection in a normal request/resource if you need that. uses MARS.Core.RequestAndResponse.Interfaces, MARS.Data.FireDAC, ..... TMyResource = class strict private protected // connection can be left away, when referring to MAIN_DB in the .ini [Context, Connection('MyDB', False)] FD: TMARSFireDAC; [Context] FRequest : IMARSRequest; public [Produces(TMediaType.APPLICATION_JSON)] function GetInfo([QueryParam('par1')] const APar1: string; const [QueryParam('par2')] APar2 : integer) : TMyInfo; end; function TMyResource.GetInfo(const APar1: string; const APar2: integer): TMyInfo; var fqry : TFDQuery; begin if not FD.Connection.NewQuery(fqry) then raise Exception.Create('Error bij aanmaken van query'); try fqry.sql.text := 'select * from ...........'; fqry.Open(); while not fqry.Eof do begin fqry.Next; ..... end; finally fqry.Free; end; end; Edited 7 hours ago by mvanrijnen 1 Share this post Link to post
Stuart Clennett 15 Posted 7 hours ago I have attached an image which may explain better. This is from the latest MARS Template; there is a ServerConnectionPool (TDataModule) that has a TFDConnection and is auto-created. There is a ServerMainDB TDataModule that contains an FDQuery; this datamodule is created once per request by each endpoint that needs it. I have just noticed that the FDQuery is attached to the TFDConnection at designtime, so maybe that is sufficient? Maybe I have overlooked the obvious. Share this post Link to post