How to connect FireDAC to Firebird 4 database without using a server (embedded mode)?

664 Views Asked by At

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

1

There are 1 best solutions below

0
On

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.