Search code examples
pythonfirebirdubuntu-22.04firebird-3.0

Python Firebird driver raise "Not a Directory" exception by connecting to or creation a database


I'm writing a Python3 script under Ubuntu 22.04.3 LTS to work with Firebird database under the Firebird3.0 server. I use the firebird.driver library. But I'm constantly getting an error "Not a directory". Even if I work with simplest cases, that look like code examples from Firebird driver documentation.

I'd tried to open the existing database using the function connect, but I got the exception such as:

  File "/home/izyakantorovich/Documents/projects/altium-db/altium-db-sync/db_builder.py", line 359, in db_copy_tables
    self.src_conn = fb.connect(self.src_db_file, user=self.USERNAME, password=self.PASSWORD, charset='utf-8')
  File "/home/izyakantorovich/.local/lib/python3.10/site-packages/firebird/driver/core.py", line 2132, in connect
    return __make_connection(False, dsn, db_config.utf8filename.value, dpb.get_buffer(),
  File "/home/izyakantorovich/.local/lib/python3.10/site-packages/firebird/driver/core.py", line 2047, in __make_connection
    att = provider.attach_database(dsn, dpb, 'utf-8' if utf8filename else FS_ENCODING)
  File "/home/izyakantorovich/.local/lib/python3.10/site-packages/firebird/driver/interfaces.py", line 1294, in attach_database
    self._check()
  File "/home/izyakantorovich/.local/lib/python3.10/site-packages/firebird/driver/interfaces.py", line 113, in _check
    raise self.__report(DatabaseError, self.status.get_errors())
firebird.driver.types.DatabaseError: operating system directive access failed
-Not a directory

The self.src_db_file is '/home/izyakantorovich/Documents/projects/altium-db/DXPSERVER.DAT' .DAT format file is some special DB compatible with Firebird software. To be honest, I don't know clearly, what is it, but the same code (with another specified path to the DXPSERVER.DAT file) pretty works under Windows.

I had also tried to just create a new database using the create_database function, but got the same exception (DatabaseError, Not a Directory etc). I ran the code below:

import firebird.driver as fb

def main():
    db = fb.create_database(database='/home/izyakantorovich/Documents/projects/altium-db/test.fdb',
                            user='SYSDBA', password='masterkey')

Paths to the databases I specified in the driver function calls seem like in proper style according to the Firebird driver documentation. What am I doing wrong?


Solution

  • There are two possible problems:

    1. you're trying to connect through a Firebird server, and the user running the server doesn't have access to your home directory, or
    2. you're connecting through Firebird embedded, and your user doesn't have access to the directory used for lock files.

    It is hard to say which is the actual problem because you use a file-path-only connection string, and then the actual connection method depends on whether or not the client library used also has access to the database engine library plugins/libEngine12.so.

    If you intend to connect through the Firebird server then:

    1. put the database in a location where the user running Firebird has access (default is generally user firebird and/or group firebird), which should not have access to your home directory, and
    2. explicitly prefix the connection string with inet://localhost/ followed by the actual path or the legacy URL prefix localhost: followed by the path to ensure the connection is made through the server and not using Firebird embedded.

    If you want to connect using Firebird embedded, make sure you're a member of the firebird group (you'll need to reload the groups after adding yourself) so you have sufficient access rights to the lock directory.

    As an aside, if this database file was copied directly from Windows, it is possible that it will not work under Linux. Moving databases between OS platforms and/or CPU platforms has to be done with a gbak backup and restore.