Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect from multiple applications to one firebird database via embedded dll

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.

like image 689
Semjon Mössinger Avatar asked Oct 02 '15 07:10

Semjon Mössinger


1 Answers

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.

like image 67
Mark Rotteveel Avatar answered Oct 17 '22 21:10

Mark Rotteveel