Click here to Skip to main content
15,867,594 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 526.2K   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

 
QuestionThe Embedded Firebird in .NET is no longer available Pin
henryagami15-Aug-16 20:44
henryagami15-Aug-16 20:44 
QuestionThe Embedded Firebird in .NET is no longer available Pin
henryagami15-Aug-16 21:31
henryagami15-Aug-16 21:31 
Questionconnection to an asp.net erp Pin
ezekielokeyo18-Jul-12 19:08
ezekielokeyo18-Jul-12 19:08 
QuestionFor those of you who're interested to get it setup on 64 bit platform (plus create db/table/insert rows) Pin
devvvy14-May-12 2:05
devvvy14-May-12 2:05 
AnswerRe: For those of you who're interested to get it setup on 64 bit platform (plus create db/table/insert rows) Pin
Dave Simon9-Feb-21 11:43
Dave Simon9-Feb-21 11:43 
Generalembedded firebird with c#.net(3.5) and vs2008 Pin
saurabh.patil@hotmail.com19-May-10 22:12
saurabh.patil@hotmail.com19-May-10 22:12 
QuestionHow Maintain Firebird Embedded Connection Open!?!?! Pin
Rafael Fernandes Brasil25-Aug-09 4:07
Rafael Fernandes Brasil25-Aug-09 4:07 
QuestionStill Supported? Pin
Jawz-X8-Sep-08 10:24
Jawz-X8-Sep-08 10:24 
AnswerRe: Still Supported? Pin
Dr.Serdar12-Sep-08 12:35
Dr.Serdar12-Sep-08 12:35 
GeneralRe: Still Supported? Pin
Jawz-X16-Sep-08 8:22
Jawz-X16-Sep-08 8:22 
Generaldoesn't work for firebird 2 Pin
ujal17-Aug-08 21:10
ujal17-Aug-08 21:10 
QuestionProblems with Stored Procedures with Embedded Firebird 2.0 Pin
dsovino17-Jan-08 7:13
dsovino17-Jan-08 7:13 
QuestionHelp Pin
K_Farhod17-Sep-07 22:46
K_Farhod17-Sep-07 22:46 
AnswerRe: Help Pin
_CloudyOne_5-Jun-08 14:01
_CloudyOne_5-Jun-08 14:01 
QuestionDLL Not Found Pin
jet858-May-07 7:31
jet858-May-07 7:31 
AnswerRe: DLL Not Found Pin
tcdavis9-May-07 6:06
tcdavis9-May-07 6:06 
GeneralRe: DLL Not Found Pin
jet8510-May-07 9:04
jet8510-May-07 9:04 
GeneralRe: DLL Not Found Pin
tcdavis10-May-07 9:14
tcdavis10-May-07 9:14 
GeneralRe: DLL Not Found Pin
balazs_hideghety16-Jul-07 3:41
balazs_hideghety16-Jul-07 3:41 
GeneralRe: DLL Not Found Pin
DaberElay31-Jan-09 10:55
DaberElay31-Jan-09 10:55 
Generalnot managed Pin
Andrew Shapira4-Feb-07 3:11
Andrew Shapira4-Feb-07 3:11 
QuestionChange the password? Pin
BJ Basañes15-Jan-07 15:39
BJ Basañes15-Jan-07 15:39 
AnswerRe: Change the password? Pin
Zoltan Balazs16-Jan-07 21:27
Zoltan Balazs16-Jan-07 21:27 
GeneralRe: Change the password? Pin
transoft8-Sep-09 9:02
transoft8-Sep-09 9:02 
GeneralRe: Change the password? Pin
Trinh Tuan4-Sep-10 16:30
Trinh Tuan4-Sep-10 16:30 

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.