DelphiFAQ Home Search:

Dynamically switch the Interbase port

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

Question:

In our environment, we have Interbase servers installed on different machines, which - for security reasons - do not listen on the default port of 3500. Some listen on port 8000 or 7000.
I'm writing a tool that shall connect to various servers (on different ports). How can I accomplish this?

Answer:

You need to modify the services file which on Windows systems is located in windowssystem32driversetc

The function SelectInterbasePort() as shown below will switch to a different port. For safety I would close connections before switching that file. It might not be a reliable situation that you are connected to multiple servers on different interbase ports simultaneously. (It might work, but I personally have not tested it.)

program Dummy;

procedure SelectInterbasePort(iPort: integer);
var
  f: TextFile;
  g: TextFile;
  Line: string;
  sServicesFn: string;
begin { SelectInterbasePort }
  sServicesFn := GetWindowsDir+'system32driversetcservices';
  AssignFile(f, sServicesFn);
  Reset(f);
  AssignFile(g, sServicesFn+'.new');
  Rewrite(g);
  while not Eof(f) do
  begin
    Readln(f, Line);
    if AnsiLowerCase(copy(Line, 1, 6))<>'gds_db' then
      writeln(g, Line);
  end; { not Eof(f) }
  CloseFile(f);
  writeln(g, 'gds_db    ', iPort, '/tcp');
  CloseFile(g);
  DeleteFile(sServicesFn);
  RenameFile(sServicesFn+'.new', sServicesFn);

  Memo1.Lines.Add('switching to port '+IntToStr(iPort));
end; { SelectInterbasePort }

begin
  SelectInterbasePort (3500);
  // do some work..
  SelectInterbasePort (8000);
  // work on other server
end.

Comments:

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: