Page 1 of 1

FirebirdSQL 3.0.7 Embedded - create database

Posted: Wed 03 Nov 2021 07:41
by ertank
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

Re: FirebirdSQL 3.0.7 Embedded - create database

Posted: Thu 04 Nov 2021 11:54
by frickler
Protocol = Local is XNET.

For embedded leave "Protocol" empty.

Re: FirebirdSQL 3.0.7 Embedded - create database

Posted: Mon 08 Nov 2021 10:22
by ViktorV
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!