1

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?)

9
  • Should have added: If I set Database to any path that exists on both the local and remote machines, it acts as if Server is set to localhost and creates a FDB on the local machine. If I set Database to 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 forcing Server to localhost regardless of what I set Server to. This is D12.2 Enterprise so FireDAC local-only restrictions should not apply. Commented Jun 30 at 15:45
  • Did you use FireDAC.Phys.FB? Otherwise, I think it defaults to the embedded driver, which can't do tcp/ip connections Commented Jun 30 at 20:03
  • @Anya - Yes. It's definitely ignoring the Server setting in the ConnectionDef, I just don't know why. If, after setting dbConn.ConnectionDefName, I set the dbConn.Params Server and Database params 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. :( Commented Jun 30 at 20:12
  • I have zero knowledge of FireDAC (or even Delphi), but is ipTCPIP the right constant? Commented Jul 1 at 13:16
  • @Mark, it is for this case. The property expects a TIBProtocol typed constant; other options like ipLocal, ipNetBEUI and ipSPX can be used where appropriate. Commented Jul 1 at 14:18

1 Answer 1

1

Changing the above code to this works.

 //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'; Pooled := FPooled; 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; //these two lines should not be necessary!! oParams := TFDPhysFBConnectionDefParams(oDef.Params); dbConn.Params.Assign(oParams); dbConn.Connected := True; except on E:Exception do begin //save the error msg and re-raise FLastError := E.Message; raise; end; end; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.