2

I want to connect to a Firebird database read-only (because the location where the .fdb is read-only for my application.

I connect like this:

conn = fdb.connect(dsn="/path/to.fdb", user='****', password='****', charset='iso8859_1')

The error I am getting is:

Error while connecting to database:\n- SQLCODE: -551\n- no permission for read-write access to database /path/to.fdb', -551, 335544352

I am using FDB v2.0. I couldn't find anything in the online documentation about a read-only connection.

Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195
  • Are you connecting through Firebird server (and if not, why not), and would that have read/write access? Do you need the database to be read-only for everyone or just this application? – Mark Rotteveel Apr 01 '19 at 14:39
  • Not through a server (because it was a hassle to set up and this worked before). The database needs to be read-only just for this application. – Bart Friederichs Apr 01 '19 at 14:42

2 Answers2

2

Unfortunately, what you want is not possible. Firebird doesn't have a concept of read-only connections. Every connection needs to be able to write information in the database for administration of transactions (this even applies for read-only transactions).

The only exception is for databases that have been marked as a read-only database using gfix. In that case, transactions piggyback on the last committed transaction id. However, marking a database read-only will make it read-only for all connections.

If your application needs read-only access, while other applications need write access to the same database, the only solution is to use Firebird server*, and use users (and roles) to assign sufficient rights to be able to read but not write to the database.


*: Firebird Embedded might be sufficient, but as the user then needs read/write access to the database, it would be simpler to circumvent this form of access control for malicious actors.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
1

Perhaps it's a good idea to create a user for the DB with a specific role, and use this role during further connections. Something like this:

$ isql firstdb.fdb -user SYSDBA -password masterkey
Database:  firstdb.fdb, User: SYSDBA
SQL> CREATE ROLE firstdbadmin;
SQL> GRANT SELECT, UPDATE, INSERT, DELETE ON sales_catalog
CON> TO ROLE firstdbadmin;
SQL> GRANT firstdbadmin TO TestAdmin;
SQL> quit;

Have you tried use 'role' argument, while creating connection? You may look here,here and here

SmartWaddles
  • 131
  • 2
  • 10