Accessing Firebird with ODBC

From LSDevLinux
Revision as of 23:02, 23 November 2010 by Spammer (talk | contribs)

Jump to: navigation, search

A guide to setting up Firebird and ODBC on a Linux system. This guide was created using Debian Etch, some details may vary for other distributions.


A few names will be used throughout this guide. These are for you to pick.

  • <code>&lt;sysdbapassword&gt;</code> The administrator password for this install of Firebird.
  • <code>&lt;database_path&gt;</code> Path to the database, eg. <code>/usr/share/fieldworks/</code>
  • <code>&lt;database_name&gt;</code> Filename for the database, eg. <code>database.fdb</code>
  • <code>&lt;username&gt;</code> Name for a regular database user.
  • <code>&lt;password&gt;</code> Password for the regular database user.
  • <code>&lt;driver_name&gt;</code> Name for the ODBC driver.
  • <code>&lt;DSN_name&gt;</code> Name for the ODBC description of the database.

Installing software

  • Install unixodbc* packages
  • Install firebird2-classic-server (set SYSDBA password)
  • Install firebird2-dev
  • Optional: Install firebird2-utils-classic

Note: It's also possible to use firebird2-super-server. I don't fully understand the difference.

Creating a database

Note: The commands run as root here would be better run as the 'firebird' user.

Note 2: Retrospectively, using this guide for Ubuntu would have probably been better. Aside from one or two package names, it should work on Debian.

# gsec -user sysdba -pass &lt;sysdbapassword&gt; -add &lt;username&gt; -pw &lt;password&gt;
$ cd &lt;database_path&gt;
# /usr/lib/firebird2/bin/isql (NOT the same as /bin/isql)
SQL> create database '&lt;datbase_name&gt;' user '&lt;username&gt;' password '&lt;password&gt;';
SQL> connect test.fdb user &lt;username&gt; password &lt;password&gt;;

Data can then be added with normal SQL commands

Setting up unixODBC


  • Download the Firebird ODBC version 2 source for Linux
  • In <code>OdbcJdbc/Builds/Gcc.lin</code> run <code>make -f makefile.linux</code>
  • Copy the resulting <code>Release/</code> into <code>/usr/lib/odbc</code>


<span style="color:red">Warning:</span> Putting the name and password in the DSN is a bit of a security risk. It is done in this example for convenience.

Graphical setup

Use ODBCConfig. Create a new Driver, then a new user DSN.

Source: The unixODBC User Manual.


  • Name: <code>&lt;driver_name&gt;</code>
  • Driver: <code>/usr/lib/odbc/</code>
  • Setup: <code>/usr/lib/odbc/</code>


First, select the driver just created and click 'OK'.

  • Name: <code>&lt;DSN_name&gt;</code>
  • Dbname: <code>localhost:&lt;database_path&gt;&lt;database_name&gt;</code>
  • User: <code>&lt;username&gt;</code>
  • Password: <code>&lt;password&gt;</code>

Config file setup

The above can also be created adding an entries to unixODBC's ini files, such as in these minimal examples. (The graphical tool does the same thing, but adds a lot more fields to the files.

Driver: <code>/etc/odbcinst.ini</code>

Driver		= /usr/lib/odbc/
Setup		= /usr/lib/odbc/

DSN: <code>/home/user/.odbc.ini<code> for a single user or <code>/etc/odbc.ini</code> for all users)

Driver   = &lt;driver_name&gt;
Dbname   = localhost:&lt;database_path&gt;&lt;database_name&gt;
User     = &lt;username&gt;
Password = &lt;password&gt;

Connecting to the database

isql -v &lt;DSN_name&gt;

(It may be required to use <code>LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/odbc</code>)

Running the above command as either root or firebird will provide an ODBC SQL console. Base can also connect to ODBC databases.

Programming (C)