Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi Client-Server Application using Firebird 2.5 embedded connection error

I have got a lengthy question to ask. First of all Im still very new when it comes to Delphi programming and my experience has beem mostly developing small single user database applications using ADO and an Access database.

I need to take the transition now to a client server application and this is where the problem starts. I decided to use Firebird 2.5 embeded as my database, as it is open source, and it is can be used with the interbase components in Delphi and that multiple clients can access the database simultanously. So I followed the interbase tutorial in Delphi. I managed to connect the client to the server and see the data in the example (While both are running on my pc), but when i tried to move the client to another pc, keeping the server on mine and running it to see if I can connect to the server it gave me the following error.

Exception EIdSocketError in module clientDemo.exe at 0029DCAC. Socket Error # 10061 Connection refused.

I understand that this might be because the host is defined as localhost in the client. But here is my first question. In the TSQLConncetion you can set die hostname under Driver->Hostname. The thing I want to know is how do you do this at run time, as I cannot get the property when I try and make an edit box to allow the user to enter the value and then set it via code like for example:

SQLConncetion1.Driver.Hostname := edtHost.text; This cannot be done this way and the only way I see you can set the hostname is with the object inspector, but that is not available at runtime and I need to set the hostname on the client when the program is running the first time, so how do you set the hostname/IP address at runtime?

Im using Delphi XE2

There is still a lot of questions to come especially when it comes to deployment, but I will take this piece by piece and I appreciate the advice.

like image 726
Japster Avatar asked Oct 23 '22 17:10

Japster


1 Answers

Embedded can't be used by multiple users at the same time (even if it's two applications on the same machine). See here for information on the differences between the three versions. There's also information in another SO question that might help.

As far as specifying a server at runtime, this may help:

procedure TForm1.Button1Click(Sender: TObject);
var 
 Conn: TSQLConnection;
begin
  Conn := TSQLConnection.Create(Self);
  try
    Conn.DriverName := 'FirebirdConnection';
    Conn.Params.Add('User_Name=SYSDBA');
    Conn.Params.Add('Password=masterkey');

    // Replace the dbname in the next line with the
    // value obtained at runtime, as  in
    // Conn.Params.Add('Database=' + YourNewPathAndDBName);
    Conn.Params.Add('Database=C:\FireBirdData\YourDB.fdb');

    Conn.Open;
    if Conn.Connected then
      ShowMessage('Connection successfully made to DB');
  finally
    Conn.Free;
  end;
end;
like image 114
Ken White Avatar answered Oct 29 '22 17:10

Ken White