5,699,997 members and growing! (17,297 online)
Email Password   helpLost your password?
Database » Database » Other databases     Intermediate

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

By Dan Letecky

An example that shows how Firebird database excels in embedding.
C#, SQL, Windows, .NET 1.1, .NET, ADO.NET, WinForms, Visual Studio, VS.NET2003, DBA, Dev

Posted: 28 Jan 2005
Updated: 28 Jan 2005
Views: 169,443
Bookmarked: 135 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
48 votes for this Article.
Popularity: 7.62 Rating: 4.53 out of 5
1 vote, 2.1%
1
1 vote, 2.1%
2
4 votes, 8.3%
3
7 votes, 14.6%
4
35 votes, 72.9%
5

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:

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:

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.

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:

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

About the Author

Dan Letecky


My open-source ASP.NET 2.0 controls:

DayPilot - Outlook-like calendar/scheduling control
DayPilot MonthPicker - Light-weight month picker
MenuPilot - Hover context menu

Location: Czech Republic Czech Republic

Other popular Database articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 105 (Total in Forum: 105) (Refresh)FirstPrevNext
QuestionStill Supported?memberJawz-X11:24 8 Sep '08  
AnswerRe: Still Supported?memberDr.Serdar13:35 12 Sep '08  
GeneralRe: Still Supported?memberJawz-X9:22 16 Sep '08  
Generaldoesn't work for firebird 2memberujal22:10 17 Aug '08  
QuestionProblems with Stored Procedures with Embedded Firebird 2.0memberkiweed8:13 17 Jan '08  
QuestionHelpmemberK_Farhod23:46 17 Sep '07  
AnswerRe: Helpmember_CloudyOne_15:01 5 Jun '08  
QuestionDLL Not Foundmemberjet858:31 8 May '07  
AnswerRe: DLL Not Foundmembertcdavis7:06 9 May '07  
GeneralRe: DLL Not Foundmemberjet8510:04 10 May '07  
GeneralRe: DLL Not Foundmembertcdavis10:14 10 May '07  
GeneralRe: DLL Not Foundmemberbalazs_hideghety4:41 16 Jul '07  
Generalnot managedmemberAndrew Shapira4:11 4 Feb '07  
GeneralChange the password?memberIsmok16:39 15 Jan '07  
GeneralRe: Change the password?memberBalazs Zoltan22:27 16 Jan '07  
QuestionHelp Help HelpmemberLinXG15:06 28 Nov '06  
AnswerRe: Help Help HelpmemberArgoDragon16:36 4 Dec '06  
Generaldemo source(embedded firebird)membernewgendb8:24 23 Nov '06  
GeneralRe: demo source(embedded firebird)memberBalazs Zoltan9:09 23 Nov '06  
GeneralRe: demo source(embedded firebird)membernewgendb9:17 23 Nov '06  
GeneralRe: demo source(embedded firebird)memberBalazs Zoltan10:07 23 Nov '06  
GeneralRe: demo source(embedded firebird)membernewgendb10:14 23 Nov '06  
GeneralRe: demo source(embedded firebird)memberBalazs Zoltan21:35 23 Nov '06  
GeneralVery interestingmemberWillemM22:16 25 Oct '06  
QuestionHelp Pleasemembertyleray6:06 10 Aug '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 28 Jan 2005
Editor: Smitha Vijayan
Copyright 2005 by Dan Letecky
Everything else Copyright © CodeProject, 1999-2008
Web07 | Advertise on the Code Project