Page 1 of 1

How to create a Firebird db on Server if not exists?

Posted: Mon 26 Jan 2015 23:08
by FredS
Got this working for SQLServer and embedded FB but I just can't figure out how to do this for a Firebird Server..

With the embedded version you can just check FileExists with SQLServer you can connect with no DB and use GetDatabaseNames, but how do you do this for Firebird?

Any help appreciated..

Re: How to create a Firebird db on Server if not exists?

Posted: Tue 27 Jan 2015 11:41
by ViktorV
You can create a database using the TIBCConnection.CreateDatabase method. Here is an example of Firebird database creation in case when no DB file exists:

Code: Select all

  IBCConnection.Database := 'database_name.fdb';
  IBCConnection.ClientLibrary := 'fbclient.dll';
  IBCConnection.Params.Clear;
  IBCConnection.Params.Add('USER ''SYSDBA''');
  IBCConnection.Params.Add('PASSWORD ''masterkey''');
  IBCConnection.Params.Add('PAGE_SIZE 4096');
  IBCConnection.Params.Add('DEFAULT CHARACTER SET WIN1251');
  try
    IBCConnection.Connect;
    ShowMessage('Connect DB');
  except
    on E : Exception do
      if Pos('The system cannot find the file specified.', E.Message) <> 0 then 
      begin
        IBCConnection.CreateDatabase;
        ShowMessage('Create DB');
      end;
  end;

Re: How to create a Firebird db on Server if not exists?

Posted: Tue 27 Jan 2015 17:35
by FredS
I am already able to create the db both on server and embedded with UniConnection, but this is what I was missing, thanks.
ViktorV wrote: try
IBCConnection.Connect;
ShowMessage('Connect DB');
except
on E : Exception do
if Pos('The system cannot find the file specified.', E.Message) <> 0 then
begin
IBCConnection.CreateDatabase;
ShowMessage('Create DB');
end;
end;
[/code]

Re: How to create a Firebird db on Server if not exists?

Posted: Wed 28 Jan 2015 09:45
by ViktorV
Feel free to contact us if you have any further questions about our product.