Create FirebirdSQL database on remote server

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

Create FirebirdSQL database on remote server

Post by ertank » Thu 25 Feb 2021 19:25

Hello,

I am using Delphi 10.3.3, UniDAC 8.3.2, FirebirdSQL 2.5.9 and targeting Win32 executable.

I have below function which works fine on computers where FirebirdSQL server is installed, my application is installed and database is created on that very same computer.

Code: Select all

function CreateFdbDatabase(const DBName, Server, DatabaseUser, DatabaseUserPassword, FBClientDll:string): Boolean;
var
  DB: TUniconnection;
  Script: TUniScript;
begin
  DB := nil;
  Script := nil;

  try
    DB := TUniConnection.Create(nil);
    DB.ProviderName := TInterBaseUniProvider.GetProviderName();
    DB.SpecificOptions.Values['ClientLibrary'] := FBClientDll;
    Script := TUniScript.Create(nil);
    Script.OnError := TMyClass.ScriptError;
    Script.Connection := DB;
    Script.NoPreconnect := True;
    Script.SQL.Add('create database ' + QuotedStr(DBName));
    Script.SQL.Add('USER ' + QuotedStr(DatabaseUser) + ' PASSWORD ' + QuotedStr(DatabaseUserPassword));
    Script.SQL.Add('PAGE_SIZE 16384 DEFAULT CHARACTER SET WIN1254');
    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;
I now need to create a database on a remote server. Lets say, My application is running on computer A and there is another computer B on same LAN. I want to create a database from A on B. When I used above function to achieve that I got below error written in my log

Code: Select all

Script Error: I/O error during "CreateFile (create)" operation for file "C:\DB\BRANCH\TEST.FDB" Error while trying to create file Sistem belirtilen yolu bulamıyor. 
I did double check that target directory exists on the remote computer. I also manually copy a firebirdsql database on that directory on remote server and I could establish a successful connection, write data in it, etc. My only problem is that I cannot remotely create a database.

Any help is appreciated.

Thanks & Regards,
Ertan

oleg0k
Devart Team
Posts: 190
Joined: Wed 11 Mar 2020 08:28

Re: Create FirebirdSQL database on remote server

Post by oleg0k » Tue 16 Mar 2021 18:35

Hello,
You should specify the server name or IP address of another computer. In your example:

Code: Select all

DBName:='ComputerB:'+DBName;
Script.SQL.Add('create database ' + QuotedStr(DBName));
wbr, Oleg
Devart Team

ertank
Posts: 172
Joined: Wed 13 Jan 2016 16:00

Re: Create FirebirdSQL database on remote server

Post by ertank » Fri 26 Mar 2021 08:23

Hello,

That did work. I also added port as an incoming parameter to my function as port is different than default in rare cases

Code: Select all

Script.SQL.Add('create database ' + QuotedStr(Server + '/' + Port.ToString() + ':' + DBName));
Thanks.
Last edited by ertank on Fri 26 Mar 2021 13:20, edited 1 time in total.

oleg0k
Devart Team
Posts: 190
Joined: Wed 11 Mar 2020 08:28

Re: Create FirebirdSQL database on remote server

Post by oleg0k » Fri 26 Mar 2021 12:51

Hello,
Glad to see that the issue was resolved.
Feel free to contact us if you have any further questions about our products.

wbr, Oleg
Devart Team

Post Reply