Database Aliasing - Firebird

Firebird release 1.5 introduced the concept of database aliasing, not just to relieve keyboard-weary developers, but also to improve the portability of applications and to tighten up control of both internal and external database file access.

aliases.conf

With database aliasing came the configuration file aliases.conf. It is located in the root directory of your Firebird server installation and should not be moved from there.

Portability

Before release 1.5, all client applications had to connect to the server using a connection string that included the absolute path to the server. The format of the absolute path varies according to whether the server is running on Windows or a POSIX-compliant platform (Linux, UNIX, etc.) and, with a Windows server, whether the clients are using TCP/IP or NetBEUI for network connectivity.

For example, suppose you have a server named “hotchicken.” With the server running on a POSIX-compliant platform, TCP/IP clients would connect to databases using a string of this format:

hotchicken:/opt/databases/Employee.fdb

With the server running on Windows, TCP/IP clients would connect with a different path format:
hotchicken:D:\databases\Employee.fdb

Database aliasing makes it so that, for TCP/IP clients, these differences become transparent. The absolute path portion of the connection string goes into the alias file, associated with a simple alias name. For example, in aliases.conf on a Linux server, the example could be stored as

db1 = /opt/databases/Employee.fdb

On a Windows server installation with TCP/IP clients, it could be

db1 = D:\databases\Employee.fdb

Regardless of whether the server is POSIX or Windows, the connection string becomes

hotchicken:db1

It is not quite so neat if you want to make it so your application’s connection string to a Windows host is transparent across either a TCP/IP or a NetBEUI connection, however. The UNC notation for a Windows host server to NetBEUI clients means that, although the database alias would be identical, the server portion is not portable:

\\hotchicken\db1

Versus

hotchicken:db1

Access Control

The principal benefit of the aliasing option is that it can be used, in combination with the firebird.conf parameter DatabaseAccess = NONE, to restrict the server to opening only a specific set of named database files, namely those identified in aliases.conf.

Database aliasing was introduced in Firebird 1.5. To implement it, edit the file aliases.conf in the root directory of your Firebird installation, using a plain text editor such as Notepad (on Windows) or vi (on Linux).

The aliases.conf File Layout

The installed aliases.conf looks similar to this:

As in all of Firebird’s configuration files, the # symbols are comment markers. To configure an alias, simply delete the # and change the dummy line to the appropriate database path:

Each connection request containing a path using the alias format causes the server to read aliases.conf. You can edit aliases.conf while the server is running. The change will not affect current connections, but future connections will use the new or modified alias.

Connecting Using an Aliased Database Path

For TCP/IP connections, using the previous aliases.conf examples, the modified connection string in your application looks like this:

Server_name:aliasname

For example:

hotchicken:fbdb2

For Windows Named Pipes connections, it looks like this:

\\hotchicken\fbdb2

For a local connection, simply use the alias on its own.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Firebird Topics