Click here to Skip to main content
15,846,346 members
Articles / Desktop Programming / Windows Forms
Article

Embedded Firebird: Full-Featured Embedded Database with 2 MB Runtime

Rate me:
Please Sign up or sign in to vote.
4.77/5 (60 votes)
28 Jan 20052 min read 524.8K   15.2K   194   116
An example that shows how Firebird database excels in embedding.

Sample Image - screenshot.gif

The advantages of Embedded Firebird

Firebird is a database with 20 years of history, full set of features (including transactions, stored procedures, hot-backup, excellent scalability, etc.) and a friendly open source license. It is an overlooked but compelling alternative to Microsoft Jet and Microsoft MSDE 2000/SQL Express 2005. Let's take a look at how it can be used embedded in your desktop application. What makes Embedded Firebird ideal for embedding:

  • The embedded runtime is < 2 MB (starting at just one DLL + one .NET assembly). The runtime is deployed by simple copying, no installation or component registration is required.
  • The database file (it's just a single file) can have any name and extension. You can associate the extension with your application.
  • The migration to a standalone server couldn't be easier. Just copy the database file to the server and change a connection string on your client.

Working with Embedded Firebird

To start using Embedded Firebird in .NET, you need to download:

  • Embedded Firebird Engine (current stable version is 1.5.2)
  • Firebird ADO.NET Provider (current stable version is 1.6.3)

After creating a new project in Visual Studio .NET, add a reference to FirebirdSql.Data.Firebird.dll (from Firebird ADO.NET Provider installation), and copy fbembed.dll (from Embedded Firebird ZIP package) to the project output directory (e.g., bin/Debug).

The Firebird ADO.NET Provider can connect to a standalone Firebird Server using a connection string like this:

C#
FbConnection c = new FbConnection("ServerType=0;User=SYSDBA;" + 
         "Password=masterkey;Dialect=3;Database=c:\\data\\mydb.fdb");

It can connect to an embedded Firebird using this connection string:

C#
FbConnection c = new FbConnection("ServerType=1;User=SYSDBA;" + 
                 "Password=masterkey;Dialect=3;Database=mydb.fdb");

The database path can be relative to fbembed.dll when using the Embedded Firebird.

You see that switching from embedded and standalone Firebird and vice versa is a piece of cake.

Creating a new database

There are two ways to create a new database:

  • Creating a database programmatically.
  • Copying an existing database template.

It's up to you which way you choose. Copying an existing database is easy (just make sure the template is not open before copying), so let's try to create it programmatically.

C#
Hashtable parameters = new Hashtable();
parameters.Add("User", "SYSDBA");
parameters.Add("Password", "masterkey");
parameters.Add("Database", @"mydb.fdb");
parameters.Add("ServerType", 1);
FbConnection.CreateDatabase(parameters);

Continue as usual

Working with Firebird ADO.NET Provider is easy. You will reuse your experience with other ADO.NET providers. It even has some nice features, like calling the stored procedures using the MSSQL style:

C#
FbCommand cmd = new FbCommand("MYSTOREDPROCEDURE", 
            new FbConnection(connectionString));
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@first", "value1");
cmd.Parameters.Add("@second", "value2");
cmd.Connection.Open();
try
{
    cmd.ExecuteNonQuery();
}
finally
{
    cmd.Connection.Close();
}

Useful Resources

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Czech Republic Czech Republic
My open-source event calendar/scheduling web UI components:

DayPilot for JavaScript, Angular, React and Vue

Comments and Discussions

 
GeneralRe: Switching between embedded and server Pin
mikejonesperficient29-Jul-05 5:41
mikejonesperficient29-Jul-05 5:41 
Generalstandalone does not work Pin
jinboh25-May-05 5:28
jinboh25-May-05 5:28 
GeneralRe: standalone does not work Pin
Dan Letecky27-May-05 1:25
Dan Letecky27-May-05 1:25 
GeneralRe: standalone does not work Pin
jinboh27-May-05 3:34
jinboh27-May-05 3:34 
GeneralRe: standalone does not work Pin
Dan Letecky27-May-05 3:43
Dan Letecky27-May-05 3:43 
GeneralRe: standalone does not work Pin
jinboh27-May-05 4:54
jinboh27-May-05 4:54 
GeneralRe: standalone does not work Pin
Dan Letecky27-May-05 5:07
Dan Letecky27-May-05 5:07 
GeneralRe: standalone does not work Pin
jinboh27-May-05 5:49
jinboh27-May-05 5:49 
Once again, many thanks for your quick reply.
I am trying to use c# to write a windows application for Firebird DB, like the Enterprise Manager for SQL Server. It should work on both server and client, and everything base on FirebirdSql.Data.Firebird.dll. I am not sure now, any idea or suggestion would be a great help.

Thanks again.
GeneralStored Procedures Pin
karlik.rslon15-May-05 9:23
karlik.rslon15-May-05 9:23 
GeneralError during Creating a Database Programmatically Pin
goatstudio6-May-05 22:10
goatstudio6-May-05 22:10 
GeneralRe: Error during Creating a Database Programmatically Pin
gabegabe16-May-05 3:28
gabegabe16-May-05 3:28 
GeneralTroubleshooting when database file path contains Chinese/Japanese characters Pin
percyboy12-Apr-05 0:43
percyboy12-Apr-05 0:43 
QuestionRequires compact? Pin
Adam Tibi12-Mar-05 6:02
professionalAdam Tibi12-Mar-05 6:02 
AnswerRe: Requires compact? Pin
Dan Letecky14-Mar-05 12:54
Dan Letecky14-Mar-05 12:54 
QuestionCharacter Sets? Pin
Adam Tibi8-Mar-05 9:17
professionalAdam Tibi8-Mar-05 9:17 
AnswerRe: Character Sets? Pin
Dan Letecky8-Mar-05 10:04
Dan Letecky8-Mar-05 10:04 
GeneralRe: Character Sets? Pin
Adam Tibi11-Mar-05 12:34
professionalAdam Tibi11-Mar-05 12:34 
GeneralRe: Character Sets? Pin
Dan Letecky14-Mar-05 12:59
Dan Letecky14-Mar-05 12:59 
GeneralFirebird + Marathon = KickA$$ Pin
ialexei14-Feb-05 6:20
ialexei14-Feb-05 6:20 
GeneralRe: Firebird + Marathon = KickA$$ Pin
Dan Letecky16-Feb-05 12:04
Dan Letecky16-Feb-05 12:04 
Generalguid Pin
Jan Vercauteren12-Feb-05 9:35
Jan Vercauteren12-Feb-05 9:35 
GeneralRe: guid Pin
Dan Letecky12-Feb-05 10:13
Dan Letecky12-Feb-05 10:13 
GeneralRe: guid Pin
Jan Vercauteren14-Feb-05 2:49
Jan Vercauteren14-Feb-05 2:49 
GeneralMarathon Pin
bertonciniluca9-Feb-05 3:03
bertonciniluca9-Feb-05 3:03 
GeneralProgamtically creating the DB objects Pin
pranav_vk6-Feb-05 20:26
pranav_vk6-Feb-05 20:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.