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

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
FredS
Posts: 272
Joined: Mon 10 Nov 2014 17:52

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

Post by FredS » Mon 26 Jan 2015 23:08

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

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

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

Post by ViktorV » Tue 27 Jan 2015 11:41

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;

FredS
Posts: 272
Joined: Mon 10 Nov 2014 17:52

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

Post by FredS » Tue 27 Jan 2015 17:35

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]

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

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

Post by ViktorV » Wed 28 Jan 2015 09:45

Feel free to contact us if you have any further questions about our product.

Post Reply