C++ Builder - Creating InterBase database on the fly at run-time using FireDAC

Posted by on in Blogs

Sometimes you have the need to create your InterBase database on the fly in code at runtime, for example, if a user downloads your application and runs the application for the first time, and your app needs to create and use a database with the application.  On Single or Multi-Device platforms, this would save you from having to deploy the database file and also setup the paths for deployment reducing your upfront work.  

From Connect to InterBase (FireDAC), looks like OpenMode=Open|Create|OpenOrCreate is what we need to create an InterBase database on the fly.  

In previous versions of FireDAC, the InterBase driver had a 'CreateDatabase' parameter, but the 'CreateDatabase' parameter has been deprecated,  but FireDAC internally still recognizes CreateDatabase=Yes|No.  With the current versions of FireDAC, instead of 'CreateDatabase', you should use OpenMode = Open | Create | OpenOrCreate, where:

Create -- creates a new database. 

OpenOrCreate -- opens an existing database or creates a new database if the specified database does not exist.

For an example using C++ Builder, here is the base code you would need:

DBPath ="MyDB.ib";

TFDConnection* FDConnection1=new TFDConnection(Form3)

FDConnection1->Params->Values["DriverID"] = "IB";

FDConnection1->Params->Values["Database"] = DBPath;

FDConnection1->Params->Values["User_Name"] = "SYSDBA";

FDConnection1->Params->Values["Password"] = "masterkey";

FDConnection1->Params->Values["OpenMode"] = "Create";



In the above example code, using OpenMode = Create, if the MyDB.ib file already exists, then FireDAC will throw this error:

EIBNativeException: [FireDAC][Phys][IB]I/O error for the file "MyDB.ib" database exists.

If you want to open the existing MyDB.ib file, then use OpenMode = OpenOrCreate.

If you need to know the names of the Parameters, you can drop a FDConnection component on the form, double-click the FDConnection component that will display the FDConnection Editor, showing all the Parameters for your FireDAC InterBase driver, like this:


A C++ Builder 10.2 Tokyo example is here, showing both deploy the database file and set the path for deployment.

Using InterBase on mobile and/or desktop devices gives many benefits, especially when you are storing local data needing full 256bit AES strength encryption. Using the properties exposed in FireDAC for InterBase, you can easily create and manage a local database on the mobile or desktop device without having to deploy one from the start. This makes deployment simpler! But, if you do need to deploy an InterBase database you can still do this as InterBase supports the same InterBase On Disk Structure (ODS) for Windows, Mac, Linux, Solaris, Android and iOS.


Gold User, Rank: 90, Points: 4
Al Mannarino has 25+ years of software development experience, including object-oriented analysis and design (OOAD) and developing and deploying production applications. He is currently a Principal Software Consultant and Evangelist for Embarcadero Technologies. Prior to joining Embarcadero, Al spent three years working with CodeGear, a division of Borland that was acquired by Embarcadero in 2008. He also worked for five years as a lead systems engineer for Borland supporting application lifecycle management, software delivery optimization and developer tools solutions. Prior to Borland, Al served as a systems engineer for companies including Objectivity, Versant, Red Brick Systems, Information Builders, and was an electrical engineer for Grumman Aerospace performing application implementations on complex electrical-mechanical systems. Al has a bachelor's of science degree in electrical engineering from Manhattan College.


Check out more tips and tricks in this development video: