5

I am relatively new to database programming. I use firebird 2.5 with IBPP. I have at least two applications using the sampe firebird database. I want to connect with the embedded variant (fbembedded.dll, icudt30.dll, icuc30.dll), since it will be a host application on customer PCs. I wrote a simple test application reading data from the database and started this application three times at the same time. Everything worked.

But now I am not shure if this works always and if this works stable without the danger to corrupt data. Because when I have a connection with the database with the viewer ibexpert my test application cannot connect to the database. Additionally, the documantation sais (firebirdEmbedded):

You can have multiple embedded servers running at the same time, and you can have multiple apps connecting to the same embedded server. Having a regular server already running isn't a problem either. However, an embedded server locks a database file for its own exclusive use after successful connection. This means that you cannot access the same database from multiple embedded server processes simultaneously (or from any other servers, once an embedded server has locked the file).

Is the documantation right? My sample application seems to show the opposite. I had a firebird superserver installed on my pc a while ago but uninstalled it before testing this.

Mark Rotteveel
  • 82,132
  • 136
  • 114
  • 158
Semjon Mössinger
  • 1,512
  • 2
  • 20
  • 28

1 Answers1

5

The document you refer to is based on Firebird 2.0 or 2.1. The 'server' architecture of Firebird Embedded on Windows was changed in Firebird 2.5. Before Firebird 2.5, Firebird Embedded on Windows behaved as SuperServer, meaning it required exclusive access to the database file.

Starting with Firebird 2.5, Firebird Embedded on Windows behaves like the SuperClassic server model, which means it uses shared access to the database files, and that the same database can be accessed by multiple Firebird Embedded applications and Firebird servers in the Classic or SuperClassic server model (but not SuperServer) if they are running on the same machine. The downside of this change is that embedded applications need to be able to create, read and write the shared database lockfiles (in C:\ProgramData\Firebird).

You don't need to worry about corruption: if the embedded engine can't access the shared lockfile, the connection will fail. The reason you can't connect with IB Expert, is probably that you attempt to connect through a Firebird server with the SuperServer model (which requires exclusive access).

See also the Firebird 2.5 release notes: Changes in the Firebird Engine:

The embedded server in the Windows library, fbembed.dll, now uses Superclassic, not Superserver as previously, thus unifying its model with that of local connection to Superclassic on POSIX. The database file-lock that previously restricted connections to a single application space is replaced by a global lock table that allows simultaneous access to the same database from different embedded server modules. This facilitates concurrent debugging of applications and use of native utility tools like gbak, gstat and so on.

Mark Rotteveel
  • 82,132
  • 136
  • 114
  • 158
  • Why is "need to be able to create, read and write the shared database lockfiles" a downside? – Semjon Mössinger Oct 02 '15 at 08:21
  • 1
    @Ergodicity I don't use embedded myself (except when testing the embedded support in the JDBC driver for Firebird), but as far as I understand running an application as a user with limited rights might cause problems if C:\ProgramData\Firebird doesn't exist yet, or the user doesn't have rights to create files and write to that path. You may need to ensure that the path exists (with the right privileges) when installing the application. – Mark Rotteveel Oct 02 '15 at 08:26
  • 1
    I no created several programs using the same database at the same time. So, connect from multiple applicatons to one firebird database via embedded dll SEEMS TO WORK in everyday use. Neither me nor the testers nor the customers had any problems in the last year. Though we didn't use special stress tests to prove it works under all conditions. – Semjon Mössinger Sep 21 '17 at 09:09