c++builderfiredacrad-server

Using FDManager with Rad Server Resources


I'm refactoring my C++/Rad Server project and wish to use the TFDManager to handle the connection definitions and Connections. As it stands each resource has it's own Connection to the DBMS, Postgres. Everything works fine, but there is too much code duplication.

I added a DataModule to the project with the FDManager and the supporting code (below). In the options build order profile the DataModule is the second class, behind the projects main class file, that's built.

I used this set up many times in other projects and it works fine.

...

FDManager->Active=true;

std::unique_ptr<TStrings> oParams = std::make_unique<TStringList>();

FDPhysPgDriverLink->VendorLib = PG_VENDOR_LIB; 

oParams->Add("DriverID=PG"); 
oParams->Add("Server=xx.xxx.xx.xxx");  
oParams->Add("Port=xxxx"); 
oParams->Add("Database=a_database"); 
oParams->Add("User_Name=my_user");  
oParams->Add("Password=my_users_password");  
oParams->Add("CharacterSet=utf8"); 
oParams->Add("Pooling=true;"); 
oParams->Add("MetaDefSchema=xxxxxx_schema");
oParams->Add("ExtendedMetadata=true");

FDManager->AddConnectionDef("PG", "PG", oParams.get());
oParams->Clear();
...

In a resource file, I make the connection in the first method invoked which is a POST method.

PgConnection->ConnectionDefName="PG"; PgConnection->Connected=true;

When I run the project, the Rad Server stand alone logs an error [FireDAC][Stan][Def]-254. Definition [PG] not found in the "FDConnectionDefs.ini" file, thus failing.

I'm using Private Connections with the FDManager->AddConnectionDef(), so I shouldn't see a log entry error and the .bpl should not be looking for the definition in the FDConnectionDefs.ini file.

Does Rad Server not allow the use of FDManager, or have I missed something?


Solution

  • The issue was with the #pragma explicit_rtti methods (public) definition in the header. Like in this article you need to use the Beforeconnect event handler method. The article is Delphi based but can port to C++ easily enough. In the article Rizzato uses the BeforeConnect event to set the definition, but I had issues with this and connected with support. The issue is that the BeforeConnect event method is declared as __published and so you need to have this pragma statement instead of the generated one. If you need more information please add to his thread.

    #pragma explicit_rtti methods (public, __published)