Jump to content

Location of FireDAC files. How can I have POOLED = true?


Bimmer

Recommended Posts

Starting to build our first UniGui project I face myself in a situation I need an answer to.

With a standard unigui login form. I would like to be able to have multiple databases available.
Not for selection - but via the users login, through our user-api that handles auth.

The database alias (an entry in firedac connections file - ConnectionDefName) is returned from our api and I now need to set the name on the TFDConnection.

function TUniMainModule.ChooseDatabaseConnection(aDatabaseConnectionDefName: string): boolean;
begin
  if FDManager.IsConnectionDef(aDatabaseConnectionDefName) then
  begin
    DBConn.Close;
    DBConn.ConnectionDefName := aDatabaseConnectionDefName;
  end;
end;

This works - but only if the setting - POOLED is set to false in my connections file.

I'm loading FDDrivers.ini (specific different vendor files) in the Creation of the servermodule.

And the Connections.ini (databases) is loaded in mainmodule creation.

Should I do anything specific to be able to use pooled=true ?

 

 

Link to comment
Share on other sites

Hi Sherzod - and thanks for joining my quest 🙂

 

Trying to use a connections.ini file with the setting - pooled=true - I get the following error when doing my login and connecting to the database.

Project SkyPOS.exe raised exception class EFDException with message '[FireDAC][Comp][Clnt]-507. 
Connection [DBConn: TFDConnection] cannot be pooled. 
Possible reason: connection definition is not in the FDManager.ConnectionDefs list or 
TFDConnection.Params has additional parameters'.

And I now that this indicates that the setup i wrong somehow. But I'm only setting the ConnectionDefName of the TFDConnection. And by doing that I should have what is defined as a persistent connection definiton

link to info here -> https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Defining_Connection_(FireDAC)

The connection is in the ConnectionDefs list - I know that because I've tried listing all connections on the login form. And all is correctly listed.

 

Link to comment
Share on other sites

I found a demo app - "DBLookupComboBox - Custom Remote Query" 

It uses pooled connection. But is doing it with a private setup. 

Let me try and modify the sample app to use a persistent setup. And see if it fails like my app. I will report back later.

Link to comment
Share on other sites

in the lib

 

type
  TConnectionDefDriverParams = record
    DriverDefName: string;
    VendorLib: string;
  end;

  TConnectionDefParams = record
    ConnectionDefName: string;
    Server: string;
    Database: string;
    UserName: string;
    Password: string;
    LocalConnection: Boolean;
    CharacterSet: string;
  end;

  TConnectionDefPoolParams = record
    Pooled: Boolean;
    PoolMaximumItems: Integer;
    PoolCleanupTimeout: Integer;
    PoolExpireTimeout: Integer;
  end;

 

 

procedure ConfigFDManagerConnectionFirebird(
  const pConnectionDefDriverParams: TConnectionDefDriverParams;
  const pConnectionDefParams: TConnectionDefParams;
  const pConnectionDefPoolParams: TConnectionDefPoolParams);
var
  lConnection: TFDCustomConnection;
  lFBConnectionDefParams: TFDPhysFBConnectionDefParams; // FIREBIRD CONNECTION PARAMS
  lFDStanConnectionDef: IFDStanConnectionDef;
  lFDStanDefinition: IFDStanDefinition;
begin
  //PARA CRIAR OU ALTERAR Й NECESSБRIO FECHAR A O FDMANGER REFERENTE A ConnectionDefName
  FDManager.CloseConnectionDef(pConnectionDefParams.ConnectionDefName);

  FDManager.ActiveStoredUsage := [auRunTime];
  FDManager.ConnectionDefFileAutoLoad := False;
  FDManager.DriverDefFileAutoLoad := False;
  FDManager.SilentMode := True; //DESATIVA O CICLO DE MENSAGEM COM O WINDOWS PARA APRESENTAR A AMPULHETA DE PROCESSANDO.
//  FDManager.Open;

  //DRIVER
  lFDStanDefinition := FDManager.DriverDefs.FindDefinition(pConnectionDefDriverParams.DriverDefName);
  if not Assigned(FDManager.DriverDefs.FindDefinition(pConnectionDefDriverParams.DriverDefName)) then
  begin
    lFDStanDefinition := FDManager.DriverDefs.Add;
    lFDStanDefinition.Name := pConnectionDefDriverParams.DriverDefName;
  end;
  lFDStanDefinition.AsString['BaseDriverID'] := 'FB'; //DRIVER BASE
  if not pConnectionDefDriverParams.VendorLib.Trim.IsEmpty then
    lFDStanDefinition.AsString['VendorLib'] := pConnectionDefDriverParams.VendorLib; //DEFINE O CAMINHO DA DLL CLIENT DO FIREBIRD.

  //CONNECTION
  lFDStanConnectionDef := FDManager.ConnectionDefs.FindConnectionDef(pConnectionDefParams.ConnectionDefName);
  if not Assigned(FDManager.ConnectionDefs.FindConnectionDef(pConnectionDefParams.ConnectionDefName)) then
  begin
    lFDStanConnectionDef := FDManager.ConnectionDefs.AddConnectionDef;
    lFDStanConnectionDef.Name := pConnectionDefParams.ConnectionDefName;
  end;

  //DEFINIЗГO DE CONEXГO: PRIVADO :: https://docwiki.embarcadero.com/RADStudio/Sydney/en/Defining_Connection_(FireDAC)
  lFBConnectionDefParams := TFDPhysFBConnectionDefParams(lFDStanConnectionDef.Params);
  lFBConnectionDefParams.DriverID := pConnectionDefDriverParams.DriverDefName;
  lFBConnectionDefParams.Database := pConnectionDefParams.Database;
  lFBConnectionDefParams.CharacterSet := csUTF8; // <<<---------------- NEGLECTED
  lFBConnectionDefParams.UserName := pConnectionDefParams.UserName;
  lFBConnectionDefParams.Password := pConnectionDefParams.Password;
  lFBConnectionDefParams.Server := pConnectionDefParams.Server;
  lFBConnectionDefParams.Protocol := TIBProtocol.ipLocal;
  if not pConnectionDefParams.LocalConnection then
    lFBConnectionDefParams.Protocol := TIBProtocol.ipTCPIP;

  lFBConnectionDefParams.Pooled := pConnectionDefPoolParams.Pooled;
  lFBConnectionDefParams.PoolMaximumItems := pConnectionDefPoolParams.PoolMaximumItems;
  lFBConnectionDefParams.PoolCleanupTimeout := pConnectionDefPoolParams.PoolCleanupTimeout;
  lFBConnectionDefParams.PoolExpireTimeout := pConnectionDefPoolParams.PoolExpireTimeout;

  //WriteOptions
  lConnection := TFDCustomConnection.Create(nil);
  try
    lConnection.FetchOptions.Mode := TFDFetchMode.fmAll; //fmAll
    lConnection.ResourceOptions.AutoConnect := False;
//    lConnection.ResourceOptions.AutoReconnect := True;  //PERDA DE PERFORMANCE COM THREAD

    with lConnection.FormatOptions.MapRules.Add do
    begin
      SourceDataType := dtDateTime; { TFDParam.DataType }
      TargetDataType := dtDateTimeStamp; { Firebird TIMESTAMP }
    end;

    lFDStanConnectionDef.WriteOptions(lConnection.FormatOptions,
                                      lConnection.UpdateOptions,
                                      lConnection.FetchOptions,
                                      lConnection.ResourceOptions);
  finally
    lConnection.Free;
  end;

  if (FDManager.State <> TFDPhysManagerState.dmsActive) then
    FDManager.Open;
end;

 

Link to comment
Share on other sites

This problem - is not a problem.

This happens because I did not clear params of my connection.

Having a blank setup page like this. 

image.png.29c94bf704053ba0e84bf15ec528887c.png

is not the same as - "there are no params"!

I made the error of reusing an earlier FDConnection component ... and that cost me some hours of debugging 😕 

image.png.63c18199da9d013c80a38d9e35b68ff9.png

And that will give the error - that the connection cannot be pooled.

Thanks all for your help in trying to help me along. And I hope this information can help others as well.

 

  • Thanks 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...