Recent

Author Topic: Lazarus Firebird remote connection problems  (Read 6890 times)

Ferke

  • New Member
  • *
  • Posts: 13
Lazarus Firebird remote connection problems
« on: February 22, 2018, 12:44:04 pm »
Hi,

I'm using Lazarus 1.6 (32 and 64 bits) with Firebird 3.0 32 bit. Lazarus is set to compile to 32 bit.
My problem is that I cannot make my program to connect to FB database remotely. If I run my program on the server everything works fine.
I have checked everything, I can connect to the database using the isql tool.

Please correct me I set something wrong.
Parameters of TIBConnection:
DatabaseName: C:\DB\DB.FDB <-- Here goes the path to DB file on the host (DB server) computer.
Host: 192.168.1.1 <-- IP address or name of the server. I tried to leave it blank and extended the DatabaseName like 192.168.1.1:C:\DB\DB.FDB

I copied the DLLs into the folder of the program. I don't know if that is necessary.
Additional question: Do I need to share the folder of the DB file on the network? I did earlier, and the DatabaseName was the path to the file from the client computer, but when I used isql tool I realized that I needed the path on the host.

Server runs in Classic mode.

Thank you very much in advance.

BR,
Ferenc

rvk

  • Hero Member
  • *****
  • Posts: 6056
Re: Lazarus Firebird remote connection problems
« Reply #1 on: February 22, 2018, 01:26:36 pm »
First of all, can you connect to the servers database with the isql tool ON THE CLIENT?

If you can, then everything should work.
Otherwise:

*) 192.168.1.1 is usually a router. Are you sure that is a real server on that IP? (check with ipconfig /all on that machine).
*) Did you add a exception rule for firebird.exe in the firewall (or disabled the firewall and possible anti-virus completely).
*) Did you install the firebirdclient on the client.
*) Open a cmd prompt on the server and type netstat -an | findstr 3050
    Is a process listening on TCP 0.0.0.0:3050 ? Otherwise you need to make sure firebird is listening on its network ip.

DLLs in the program directory shouldn't be necessary (they also weren't on the server when you tested, I assume)

Ferke

  • New Member
  • *
  • Posts: 13
Re: Lazarus Firebird remote connection problems
« Reply #2 on: February 22, 2018, 01:33:27 pm »
First of all, thanks for your answer, very appreciated. :)

First of all, can you connect to the servers database with the isql tool ON THE CLIENT? Yes.

) 192.168.1.1 is usually a router. Are you sure that is a real server on that IP? (check with ipconfig /all on that machine). This IP is fake in my example. In fact that is home server with fix IP.
*) Did you add a exception rule for firebird.exe in the firewall (or disabled the firewall and possible anti-virus completely). Ports are open and I could connect withthe ISQL tool.
*) Did you install the firebirdclient on the client. No. That is missing. I thought the DLL-s should be enough.
*) Open a cmd prompt on the server and type netstat -an | findstr 3050
    Is a process listening on TCP 0.0.0.0:3050 ? Otherwise you need to make sure firebird is listening on its network ip.
Yes, this was the first thing I checked earlier.

DLLs in the program directory shouldn't be necessary (they also weren't on the server when you tested, I assume). Okay.

Thanks, I will make a test with the client nstallation.

 :)

Ferke

  • New Member
  • *
  • Posts: 13
Re: Lazarus Firebird remote connection problems
« Reply #3 on: February 22, 2018, 03:52:25 pm »
The client install did not help...  %)
« Last Edit: February 22, 2018, 06:22:48 pm by Ferke »

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: Lazarus Firebird remote connection problems
« Reply #4 on: February 22, 2018, 06:00:48 pm »
Some properties for you to check (TIBConnection, TSQLQuery and TSQLTransaction components):
http://wiki.freepascal.org/SqlDBHowto#How_to_connect_to_a_database_server.3F
http://wiki.freepascal.org/Firebird
http://forum.lazarus.freepascal.org/index.php/topic,37238.msg249685.html#msg249685
http://forum.lazarus.freepascal.org/index.php/topic,34145.msg222957.html#msg222957
http://forum.lazarus.freepascal.org/index.php/topic,3485.msg122877.html#msg122877

Code: Pascal  [Select][+][-]
  1. function CreateDataBaseConnection(): integer;
  2.   begin
  3.     FConnection := TIBConnection.Create(nil);
  4.     FTransaction := TSQLTransaction.Create(nil);
  5.     Result := 0;
  6.     try
  7.       try
  8.         FConnection.HostName := 'myHost';
  9.         FConnection.DatabaseName := 'myDataBaseName.gdb';
  10.         FConnection.UserName := 'sysdba';
  11.         FConnection.Password := 'masterkey';
  12.         FConnection.CharSet := 'ISO8859_1';
  13.         FConnection.Dialect := 3;
  14.         FConnection.Params.Add('PAGE_SIZE=8194');
  15.         FConnection.LoginPrompt := False;
  16.         FTransaction.Active := False;
  17.         FConnection.Connected := True;
  18.  
  19.         FTransaction.DataBase := FConnection;
  20.         FTransaction.Params.Add('isc_tpb_read_committed');  // Transaction isolation levels
  21.         FTransaction.Params.Add('isc_tpb_read');            // Access mode
  22.         FTransaction.Params.Add('isc_tpb_nowait');          // Lock resolution
  23.         FTransaction.Params.Add('isc_tpb_rec_version');     // Record versions
  24.  
  25.         FTransaction.StartTransaction;
  26.  
  27.         Result := GetSQLResult();
  28.  
  29.       except
  30.         on e: Exception do
  31.         begin
  32.           WriteLn('Error ', e.Message);
  33.         end;
  34.       end;
  35.     finally
  36.       FTransaction.Commit;
  37.       FTransaction.Free;
  38.       FConnection.Connected := False;
  39.       FConnection.Free;
  40.     end;
  41.   end;

rvk

  • Hero Member
  • *****
  • Posts: 6056
Re: Lazarus Firebird remote connection problems
« Reply #5 on: February 22, 2018, 06:24:44 pm »
@valdir.marcos, the program worked on the server, so I guess everything is set correctly.

If I run my program on the server everything works fine.
Ferenc, did you use the same host-settings (i.e. IP of the local network) in the program when testing on the server?

With the client installation of Firebird 3.0, do you still get the option on the last page to create a legacy gds32.dll in the Windows-directories?
Try a client install with checking that option.

I see the TIBConnection first searches for fbclient.dll and then for gds32.dll. But the fbclient.dll is not in the search path and needs to be extracted from registry settings. If that's not done the fbclient.dll can't be found. You could try to copy the fbclient.dll in your program directory but it could be that it needs extra files.

(also note that for a 64bit installation the 32bit fbclient.dll is in WOW64)

*) So first try the 32bit client install again on the workstation to see if you can install the legacy dll.
*) Second, copy the fbclient.dll (make sure you have the correct bitness) to your program directory.
*) Third, remove it again and make sure your firebird-bin directory is in the system search path (possible restart required).

« Last Edit: February 22, 2018, 06:26:17 pm by rvk »

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106

Ferke

  • New Member
  • *
  • Posts: 13
Re: Lazarus Firebird remote connection problems
« Reply #7 on: February 22, 2018, 08:16:41 pm »
Thank you very muck all of you!

The biggest problem was that the database aliases do not seem to work for me for an unknown reason.
The server runs on Windows 10, and I used this format: mydb = c:\db\db.fdb

After using absolute path I found immediately a small fault in my code as well.

Anyway, if somebody could help me with the aliases, that would be great.

Thank you again!  You have a beer on me! :D

rvk

  • Hero Member
  • *****
  • Posts: 6056
Re: Lazarus Firebird remote connection problems
« Reply #8 on: February 22, 2018, 08:20:18 pm »
The biggest problem was that the database aliases do not seem to work for me for an unknown reason.
The server runs on Windows 10, and I used this format: mydb = c:\db\db.fdb
After using absolute path I found immediately a small fault in my code as well.
I never used aliases with Firebird. Why would you want to? Why not just supply the hostname or ip and the absolute path to the database? (I save this in an ini file for my application)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Lazarus Firebird remote connection problems
« Reply #9 on: February 22, 2018, 08:33:44 pm »
The biggest problem was that the database aliases do not seem to work for me for an unknown reason.
The server runs on Windows 10, and I used this format: mydb = c:\db\db.fdb
After using absolute path I found immediately a small fault in my code as well.
I never used aliases with Firebird. Why would you want to? Why not just supply the hostname or ip and the absolute path to the database? (I save this in an ini file for my application)
because knowing the full path is both a security bridge and a inelegant implementation. The client application should not know anything about the server environment or at least the absolute minimum to function.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Ferke

  • New Member
  • *
  • Posts: 13
Re: Lazarus Firebird remote connection problems
« Reply #10 on: February 22, 2018, 08:56:04 pm »
The biggest problem was that the database aliases do not seem to work for me for an unknown reason.
The server runs on Windows 10, and I used this format: mydb = c:\db\db.fdb
After using absolute path I found immediately a small fault in my code as well.
I never used aliases with Firebird. Why would you want to? Why not just supply the hostname or ip and the absolute path to the database? (I save this in an ini file for my application)
because knowing the full path is both a security bridge and a inelegant implementation. The client application should not know anything about the server environment or at least the absolute minimum to function.

This is the reason exactly. And I have to find the solution.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Lazarus Firebird remote connection problems
« Reply #11 on: February 22, 2018, 09:00:18 pm »
This is the reason exactly. And I have to find the solution.
so what does your alias file look like?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

rvk

  • Hero Member
  • *****
  • Posts: 6056
Re: Lazarus Firebird remote connection problems
« Reply #12 on: February 22, 2018, 09:15:28 pm »
You did read the release notes for Firebird 3.0, right  :D

https://www.firebirdsql.org/file/documentation/release_notes/html/en/3_0/rnfb30-compat-aliasesconf.html
Quote
aliases.conf Is No More
The file aliases.conf is replaced by databases.conf in the Firebird root directory. The format for database aliases has not changed so you can copy/paste the contents of your existing aliases.conf file into databases.conf successfully. The new file is capable of carrying a lot more configuration detail, however, to enable database-level configuration of many features that were previously available only at the global server level.

Ferke

  • New Member
  • *
  • Posts: 13
Re: Lazarus Firebird remote connection problems
« Reply #13 on: February 22, 2018, 09:26:43 pm »
This is the reason exactly. And I have to find the solution.
so what does your alias file look like?

Hi!

No, it was my mistake. I use Firebird on Linux and Windows at the same time for testing purposes. I used slash instead backslash...
Still interesting why the slash did not work, since the config file contains this part as vell:

# Example Database:
#
employee.fdb = $(dir_sampleDb)/employee.fdb
employee = $(dir_sampleDb)/employee.fdb

Anyway, thank you very much!

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Lazarus Firebird remote connection problems
« Reply #14 on: February 22, 2018, 10:27:55 pm »
You did read the release notes for Firebird 3.0, right  :D

https://www.firebirdsql.org/file/documentation/release_notes/html/en/3_0/rnfb30-compat-aliasesconf.html
Quote
aliases.conf Is No More
The file aliases.conf is replaced by databases.conf in the Firebird root directory. The format for database aliases has not changed so you can copy/paste the contents of your existing aliases.conf file into databases.conf successfully. The new file is capable of carrying a lot more configuration detail, however, to enable database-level configuration of many features that were previously available only at the global server level.
Nope I haven't installed 3 yet. Thanks for the heads up.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018