FirebirdSQL 3.0.7 Embedded - create database

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ertank
Posts: 172
Joined: Wed 13 Jan 2016 16:00

FirebirdSQL 3.0.7 Embedded - create database

Post by ertank » Wed 03 Nov 2021 07:41

Hello,

I am using Delphi 10.4, UniDAC 8.3.2, FirebirdSQL 3.0.7 Win32

I can successfully create databases using UniDAC if FirebirdSQL is running as a server. When I try the same using embedded connection, I get below error:

Code: Select all

Unable to complete network request to host "xnet://Global\FIREBIRD"
My knowledge, when FirebirdSQL is in embedded mode, only provider available is "Engine12". So, XNET and TCP connection is not possible.

Identical code can create a database successfully if there ls a server service running. I am sharing my database create function below.

Code: Select all

function CreateFdbDatabase(const DBName, Server, DatabaseUser, DatabaseUserPassword, FBClientDll: string; const Codepage: string = 'WIN1254'; const Port: Word = 3050): Boolean;
var
  DB: TUniconnection;
  Script: TUniScript;
begin
  DB := nil;
  Script := nil;
  try
    DB := TUniConnection.Create(nil);
    DB.ProviderName := TInterBaseUniProvider.GetProviderName();
    DB.Server := Server;
    DB.Port := Port;
    DB.SpecificOptions.Values['ClientLibrary'] := FBClientDll;
    if DB.Server.IsEmpty then // When embedded, this is empty
      DB.SpecificOptions.Values['Protocol'] := 'Local'; // We must switch to Local for embedded

    Script := TUniScript.Create(nil);
    Script.OnError := TMyClass.ScriptError;
    Script.Connection := DB;
    Script.NoPreconnect := True;
    if not Server.IsEmpty then
      Script.SQL.Add('create database ' + QuotedStr(Server + '/' + Port.ToString() + ':' + DBName))
    else
      Script.SQL.Add('create database ' + QuotedStr(DBName));
    Script.SQL.Add('USER ' + QuotedStr(DatabaseUser) + ' PASSWORD ' + QuotedStr(DatabaseUserPassword));
    Script.SQL.Add('PAGE_SIZE 16384');
    if not Codepage.IsEmpty then
      Script.SQL.Add('DEFAULT CHARACTER SET ' + Codepage);

    try
      Script.Execute();
    except
      on E: Exception do
      begin
        if Assigned(FirebirdSQLLog) then FirebirdSQLLog.LogError('Script Error: ' + E.Message);
        Exit(False);
      end;
    end;
    Result := True;
  finally
    Script.Free();
    DB.Free();
  end;
end;
Moreover, I first asked in FirebirdSQL support group and got confirmation that it is actually possible to create databases using embedded FirebirdSQL. Example I am provided is TIBDatabase (IBX) is capable of doing that.

I would like to learn if there is anything I am overlooking at for the embedded database creation. I appreciate any help.

Thanks & Regards,
Ertan

frickler
Posts: 37
Joined: Wed 04 Apr 2018 08:30

Re: FirebirdSQL 3.0.7 Embedded - create database

Post by frickler » Thu 04 Nov 2021 11:54

Protocol = Local is XNET.

For embedded leave "Protocol" empty.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: FirebirdSQL 3.0.7 Embedded - create database

Post by ViktorV » Mon 08 Nov 2021 10:22

Hey guys!

Thank you for contacting us and for your inquiry!
Please be informed that we have fixed this behavior in UniDAC version 8.4.1.
To resolve the issue you described, you are recommended to install UniDAC 8.4.1 or newer version.

Should you have any questions, do not hesitate to ask!

Post Reply