1

I would like to be able to connect my Delphi/FireDAC application directly to a Firebird 4 database file without installing the service. I expected to be able to do this by using the local protocol, and just specifying the file. However, I get the following error.

[FireDAC][Phys][FB]Unable to complete network request to host "xnet://Global\FIREBIRD"..

I am using fbclient.dll and the zip file version of the firebirdsql distribution. I do not want to install the service.

I hope to be able to have a bunch of program files in a directory e.g. USB memory storage, such as my executable and firebird zip distribution content, plug it in to a windows computer and load my program without installing anything onto the computer.

Please tell me how can this be done?

(Many of the answers online are about older versions of firebird such as firebird 2.5 which had fbembed.dll which is no longer a part of firebird. I found this page https://ib-aid.com/download/docs/fb4migrationguide.html#_installing_embedded which had some guidance, but not enough to get me to connect firedac sucessfully).

Jared Davison
  • 333
  • 3
  • 11
  • 1
    Which Delphi version are you using? Currently FB4 is supported in Delphi 11 only. Also make sure you have Embedded checked in the TFDPhysFBDriverLink instance. – Uwe Raabe Aug 01 '23 at 12:23
  • I have Delphi 11.3 and have the TFDPhysFBDriverLink instance on the datamodule. I can connect via local protocol if I start the "firebird.exe -a", but I hoped not to have to do that. Furthermore, I see there are Android kits now for firebird, so I hope to be able to use that in a similar fashion to how IB2Go could be used on android. – Jared Davison Aug 01 '23 at 12:36
  • with TFDPhysFBDriverLink i have tried the Embedded checkbox on too. VendorLib fbclient.dll. VendorHome the firebird zip dir. BaseDriverID FB. Have tried DriverID blank and DriverID=FB. – Jared Davison Aug 01 '23 at 12:37
  • With my end goal for Android (which is beyond this question) there is an article: https://sourceforge.net/p/zeoslib/wiki/How%20to%20use%20Firebird%204.0%20with%20Zeos%20on%20Android/ To me this shows it is possible to do what I'm asking, with firebird. For now, doing this on Windows would be enough. – Jared Davison Aug 01 '23 at 12:46
  • 1
    Assuming you're using the entire contents of the Firebird zip, and reference its fbclient.dll, and not some fbclient.dll in isolation, it should work. The fact it tries an XNET connection suggests you're using an fbclient.dll which doesn't have the rest of the Firebird binaries (and specifically `plugins/engine13.dll`, which is the database engine), so it can't create an embedded connection. This could also happen if your application is 32-bits and you downloaded the 64-bit Firebird, and have a 32-bit client library elsewhere on the PATH (or vice-versa). – Mark Rotteveel Aug 01 '23 at 14:25
  • Thank you for the ideas! Ok, one mistake I made was trying to use Delphi connection tester, so of course that is 32-bit. I have just got FireDAC in design time to connect, by switching to the Firebird-4.0.2.2816-0-Win32. My application (64-bit) was meant to using the Firebird-4.0.2.2816-0-x64 so I will investigate to see what happens there. – Jared Davison Aug 02 '23 at 10:43

1 Answers1

2

Thank you to Mark Rotteveel who led me to the solution in his comment above.

For reference, here's a minimal but complete console application that sets everything up that's required.

program TestEmbeddedFB;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  System.Classes,
  FireDAC.Stan.Def,
  FireDAC.Comp.Client,
  FireDAC.Phys.FB,
  FireDAC.Phys.FBDef;

var
  FDPhysFBDriverLink1: TFDPhysFBDriverLink;
  FDConnection1: TFDConnection;

{ Make sure FBClientDLL_Path has the unzipped files
   either the 'Firebird-4.0.2.2816-0-x64' or 'Firebird-4.0.2.2816-0-Win32' etc
   - use the one that matches the platform of the this program

   Minimal set of files are documented here:
   https://ib-aid.com/download/docs/fb4migrationguide.html#_installing_embedded

   This program was tested with these:
          .
          ├── fbclient.dll
          ├── firebird.conf
          ├── firebird.msg
          ├── ib_util.dll
          ├── icudt63.dll
          ├── icudt63l.dat
          ├── icuin63.dll
          ├── icuuc63.dll
          ├── intl
          │   ├── fbintl.conf
          │   └── fbintl.dll
          ├── msvcp140.dll
          ├── plugins
          │   └── engine13.dll
          └── vcruntime140.dll

          2 directories, 13 files
 }
procedure ConnectToDB(Filename: string; FBClientDLL_Path: string);
begin
  FDPhysFBDriverLink1.VendorHome := ExtractFileDir(FBClientDLL_Path);
  FDPhysFBDriverLink1.VendorLib := ExtractFilename(FBClientDLL_Path);
  FDPhysFBDriverLink1.Embedded := True;

  FDConnection1.DriverName := 'FB';

  FDConnection1.Params.Values['Server'] := '';
  FDConnection1.Params.Values['Protocol'] := 'Local';

  FDConnection1.Params.Values['Database'] :=  Filename;
  FDConnection1.Params.Values['Username'] := '';
  FDConnection1.Params.Values['Password'] := '';

  FDConnection1.Open;
end;

var
  DbFile: string;
  FBClient: string;
begin
  try
    if not FindCmdLineSwitch('db', DbFile) then
      raise Exception.Create('Specify -db (path to fdb file)');
    if not FindCmdLineSwitch('fbclient', FBClient) then
      raise Exception.Create('Specify -fbclient (path to fbclient.dll)');

    FDPhysFBDriverLink1 := TFDPhysFBDriverLink.Create(nil);
    try
      FDConnection1 := TFDConnection.Create(nil);
      try
        ConnectToDB(DbFile, FBClient);
      finally
        FDConnection1.Free;
      end;
    finally
      FDPhysFBDriverLink1.Free;
    end;
    writeln('connected to !' + DbFile);
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
Jared Davison
  • 333
  • 3
  • 11