Using Delphi 12.2 Enterprise with FireDAC and Firebird 2.5, I'm trying to connect to a DB via the following code:
type TFD3Base = class(TDataModule) dbConn: TFDConnection; private FDBHost: String; FDBName: String; FPooled: Boolean; FLastError: String; FConDefName: String; {...} public //connects to the specified database procedure Connect(const AHost, AFDB: String); //create our tables if they don't exist procedure CreateTables; {...} end; procedure TFD3Base.Connect(const AHost, AFDB: String); var oDef: IFDStanConnectionDef; oParams: TFDPhysFBConnectionDefParams; begin //clear our datamodule's internal vars FLastError := ''; FDBHost := AHost; FDBName := AFDB; FConDefName := 'BWPMgr_1'; //if we're already connected, drop it if dbConn.Connected then begin dbConn.Connected := False; try FDManager.CloseConnectionDef(FConDefName); except end; end; //does our definition exist? oDef := FDManager.ConnectionDefs.FindConnectionDef(FConDefName); if not Assigned(oDef) then begin //no; create it oDef := FDManager.ConnectionDefs.AddConnectionDef; oDef.Name := FConDefName; //build params oParams := TFDPhysFBConnectionDefParams(oDef.Params); with oParams do begin DriverID := 'FB'; Protocol := ipTCPIP; Server := FDBHost; Database := FDBName; UserName := 'sysdba'; Password := 'masterkey'; OpenMode := omOpenOrCreate; end; //apply the changes oDef.MarkPersistent; oDef.Apply; end; //connect to the FDB if we can try dbConn.ConnectionDefName := FConDefName; dbConn.Params.Pooled := FPooled; dbConn.Connected := True; except on E:Exception do begin //save the error msg and re-raise FLastError := E.Message; raise; end; end; //if we get here, we're connected; create tables as needed CreateTables; {...} end; FDManager is configured to not autoload and is cleared so that no connection definitions exist when the program starts.
If I set Server to localhost and Database to a local drive\folder\filename, everything works as expected, the .FDB is created if it doesn't exist and opened. If I set Server to the IP address of a machine on our VPN network (which has Firebird 2.5 server installed) and Database to a drive\folder\filename local to that machine (which happens to be the same drive\folder name as on my local machine), the program does not create the .FDB on that machine, instead it opens the already-existing local .FDB.
How do I get it to connect to the remote .FDB (creating the .FDB if it doesn't exist?)
Databaseto any path that exists on both the local and remote machines, it acts as ifServeris set to localhost and creates a FDB on the local machine. If I setDatabaseto a path that exists on the remote but not locally, I get a "Path not found" error trying to create the FDB. In other words, it seems to be forcingServerto localhost regardless of what I setServerto. This is D12.2 Enterprise so FireDAC local-only restrictions should not apply.use FireDAC.Phys.FB? Otherwise, I think it defaults to the embedded driver, which can't do tcp/ip connectionsServersetting in the ConnectionDef, I just don't know why. If, after settingdbConn.ConnectionDefName, I set thedbConn.ParamsServerandDatabaseparams again, it then connects to the remote machine and creates the empty FDB. But that doesn't seem right, and isn't in line with the examples. I'm sure I'm doing something fundamental wrong, I just don't know what it is. :(ipTCPIPthe right constant?