Find out if this is a local machine

I have an implementation inside my application that should only run if my executable is on the same computer as the database.

I have a connection string that includes the server address. In case it is a local machine, which may be 127.0.0.1, localhost or something else (for example, aliases).

Is there a way to confidently check if the server in my connection string is a local machine?

+4
source share
3 answers

Extract the local transport protocol (see Connection String Frequency ) will force a local connection.

Note that with FireBird 2.0, the base implementation of local transport protocol has changed to XNET .
You should not notice any differences.

Note. Do not try to mix TCP/IP and local transport protocol for InterBase 6.0 and below, as the error can lead to data corruption.
Mixing the two with Firebird should be great.

- Jeroen

+3
source

Just set the IP address of the database in your connection with 127.0.0.1. If this fails, it is not a local machine.

Note: this may also fail if you execute your code on the computer hosting this database + the database is not configured correctly ...

0
source

And for a completely different approach:

Create two stored procedures in the database.

  • The one that returns the (custom) full path to the text file file local to the machine on which the database is running.
  • One that writes some transferred to text in this file.

In your application:

  • a call to a stored procedure that returns a file name
  • delete this file on the machine where the executable is running
  • a call to a stored procedure that writes a file and passes it a unique text (preferably unique to each call to the stored procedure)
  • make sure that you can read the file from a local location and that it contains the text that you sent to the stored procedure.

Just remember to map drives (so check if the drive in the returned file name is a local drive and not mapped) and file names (make sure the machine name matches the name of the local machine).

0
source

Source: https://habr.com/ru/post/1334651/


All Articles