Firebird Events and Firewall Issue (TIBEvents)

此生再无相见时 提交于 2019-12-24 07:45:08

问题


I would use the power of Firebird Events with delphi application with TIBEvents component.

The problem is the firewall, not every time have the correct role and when I try to register the events the application stops responding and I must wait...

How can I do?

I also try to call register function in a separated thread but with the same result.

function RegisterEvents(data : Pointer) : Integer;
begin
  with Form1 do begin
    DBOspitiEvent.Registered := true; 
  end;
end; //<-- AFTER THIS, APPLICATION IS BLOCKED (for a while)

procedure TForm1.Button2Click(Sender: TObject);
var
  ThreadId : Cardinal;
  ThreadHandle : Integer;
begin
  ThreadHandle := BeginThread(nil,0,@RegisterEvents,nil,0,ThreadId);
  if ThreadHandle = 0
    then ShowMessage('Error');
end;

回答1:


For events, a client needs to establish a separate connection, and by default Firebird uses a random port for this. In combination with firewalls, this leads to problems because the port is - for example - not allowed.

You can configure Firebird to use a fixed port, by editing firebird.conf and setting the RemoteAuxPort to a fixed value (eg 3051), and restarting Firebird. You can then configure your firewall to allow this port.

See also How to configure events with firewall?




回答2:


We had many problems with TIBEvent components since XP SP3 too.
Here is what works perfectly fine for us since than, even with newest Win10 updates:

  • We use UIB for receiving events. TUIBEvents component. (You may keep IBX for everything else... but UIB is better and faster and FB3.0 compatible.)
  • Do not execute any long-lasting code inside OnEvent procedure, but rather set multithread-safe variables to mark, what event you received (last time)
  • Deal with those variable inside each window locally. (For example: running a timer that checks and compares last-event-time with local last-refresh-time.)
  • If you are running SQL queries in a separate Thread, always create new database + transaction component, DO NOT USE the one from the main thread!
  • Open 3050 and 3051 TCP ports on Firewall!
  • We also add "fbserver.exe" file to Firewall exception and to Defender exception.
  • Set fixed ports in "firebird.conf" file: RemoteServicePort=3050 and RemoteAuxPort=3051

You may create a single FirstInstallScrip.bat file to do all these firewall changes and copies a pre-edited .conf file to FB's directory, overwriting the original one.

And YES, you can create these simple text files easily from Delphi and run it from there. Or notify the user if not ran yet. (You can read the original config file and compare those settings.)

    @ECHO program in
    @NETSH advfirewall firewall add rule name="FirebirdSQL szerver" program="%programfiles%\Firebird\Firebird_2_5\bin\fbserver.exe" profile=public,private,domain dir=in action=allow edge=yes description="FirebirdSQL Database engine"

    @ECHO program out
    @NETSH advfirewall firewall add rule name="FirebirdSQL szerver" program="%programfiles%\Firebird\Firebird_2_5\bin\fbserver.exe" profile=public,private,domain dir=out action=allow  description="FirebirdSQL Database engine"

    @ECHO ports in
    @NETSH advfirewall firewall add rule name="FirebirdSQL portok" localport=3050-3051 protocol=tcp profile=public,private,domain dir=in action=allow edge=yes description="FirebirdSQL Database engine ports"

    @ECHO ports out
    @NETSH advfirewall firewall add rule name="FirebirdSQL portok" localport=3050-3051 protocol=tcp profile=public,private,domain dir=out action=allow description="FirebirdSQL Database engine ports"

    @pause

As @Victoria suggested: use better business logic!

  1. You may store your data (red from DB) in PC's memory and show it from there.
  2. Create triggers inside your FB database self-updating the last modification.
  3. Do not delete rows, just mark them as "deleted".
  4. check only "what changed" SELECT * from "Customers" c where c.MODIFIED > '2019...' and compare with data already downloaded before, to reduce SQL load.
  5. use separate, short-time transaction to write data into DB.


来源:https://stackoverflow.com/questions/49918075/firebird-events-and-firewall-issue-tibevents

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!