Firebird Documentation IndexIsql - Interactive SQL → Connecting To A Database
Firebird Home Firebird Home Prev: Starting An Isql SessionFirebird Documentation IndexUp: Isql - Interactive SQLNext: Creating A Database

Connecting To A Database

Using Database Alias Names

A sample database named employee.fdb is located in the examples/empbuild subdirectory of your Firebird installation. Users can use this database to experiment with Firebird.

It is possible to connect to a database using isql in two ways: locally and remotely.

Note

Firebird is slash agnostic and automatically converts either type of slash to suit the relevant operating system.

Using Database Alias Names

In the examples above, we have been using the full path to the database file. This has a disadvantage in that all clients will be able to determine exactly where the database is to be found, or, may cause problems when the database has to be moved. To alleviate these problems, database aliases can be used.

Once Firebird has been installed, a file named aliases.conf can be found in the main installation folder. By adding an entry to this folder, the full path to the database can be simplified to an alias name. This makes connecting easier, hides the actual database path from inquisitive users and allows the database to be moved around as necessary without having to change all the clients to allow them to connect to the database at the new location.

To create an alias for the database currently known as /databases/firebird/MY_EMPLOYEE.FDB on the cosmos Linux server, we need to add the following to the aliases.conf file on the cosmos server. By default, this will be in the folder /opt/firebird. On Linux, this file is owned by the root user and so, must be updated by the root user. On Windows, you need to be either an administrator, a power user or SYSTEM to change the file.

my_employee = /databases/firebird/MY_EMPLOYEE.FDB

There should be no quotes around the path to the database file.

Regardless of where the database file is currently located, or if it has its physical filename renamed, etc, all the local users will refer to the database simply as my_employee. Remote users will refer to this database as cosmos:my_employee. The following example shows an isql session being connected locally to the database using the alias name rather than a full path:

cosmos> /opt/firebird/bin/isql my_employee
Database:  test, User: sysdba

SQL>

Alternatively, a remote connection would be made as follows, specifying the server name and the database alias together:

C:\Program Files\Firebird\Firebird_2_0\bin>isql cosmos:my_employee
Database:  cosmos:my_employee

SQL>

Because the alias is defined on the server where the database resides, then the remote client needs to supply the server name and the alias name (as defined on that server) in order to make a connection.

Using the CONNECT command in an existing isql session is equally as simple using alias names:

SQL> CONNECT 'cosmos:my_employee;
Database:  cosmos:my_employee

SQL>

Caution

Regarding the security aspect of using database alias names to hide the full path to the actual database file(s), it's not really all that secure as the following SQL command shows:

SQL> select MON$DATABASE_NAME from mon$database;

MON$DATABASE_NAME
=================================
/data/databases/firebird/test.fdb
Prev: Starting An Isql SessionFirebird Documentation IndexUp: Isql - Interactive SQLNext: Creating A Database
Firebird Documentation IndexIsql - Interactive SQL → Connecting To A Database