SIL LSDev Linux Development

Language software for Linux and Mac OS X

.NET LINQ to Firebird

Since we’re porting from SQL Server to Firebird, code that works on both RDBMSs is highly valuable. We want to connect to either using C#.

Microsoft’s ADO.NET Entity Framework does just that. One of the components is LINQ. Here is a beginner’s application to show how to do it with Firebird.

Download and run the latest Firebird Data Provider for .NET and Mono.

Open Visual Studio 2008 (VS). You can try using 2005, but I couldn’t get it to work. Create a new project. (File/New/Project…) Under “Project types” select Windows. Under Templates select Console Application. Give it a name. (I used LinqToFirebird.) Give the project a location. I prefer to leave the checkbox “Create directory for solution” unchecked, to avoid a deeper directory tree than I want.

In VS, go to the Solution Explorer. We’re going to add a reference to the Firebird .NET Data Provider. Right-click on References. A dialog will appear. Select the Browse tab. Go to the directory where you installed the provider and select FirebirdSqlData.FirebirdClient.dll

Now we get to code. In Program.cs, add the following above namespace at the top:

using System.Data;
using FirebirdSql.Data.FirebirdClient;

In the Main method, use the following code. You will have to change the connection string to your own, of course. (The best site for database connection strings is Microsoft has a number of examples for LINQ.

FbConnection con = new FbConnection(
“ServerType=0;User=SYSDBA;Password=masterkey;Dialect=3;” +

FbDataAdapter fbadapt = new FbDataAdapter(

// Table mappings
fbadapt.TableMappings.Add(“Table0″, “CharSets”);
DataSet dataset = new DataSet();

// Fill the dataset with a call to the database

// Query
DataTable CharSets = dataset.Tables[0];
var queryCharSets =
from rCharSets in CharSets.AsEnumerable()
select rCharSets;

foreach (DataRow rCharSets in queryCharSets)

// pause


10 Responses to “.NET LINQ to Firebird”

  1. I’m curious to know why Firebird has been chosen as a database engine out of the many other RDBMSs out there, such as MySQL. I’m a Mac person (and to a lesser degree linux) and very interested in developments in this area. Till now I’ve ended up resorting to making my own tools for linguistic data processing since most of the SIL software seems to require windows. Having fieldworks data available in a way more open than SQL Server allows would be very interesting, but my only experience to date has really been with MySQL. Are there performance or openness or usability benefits with Firebird?

  2. Steve Miller says:

    I get this question from time to time. It’s worth a separate blog entry, and I’ll try to post one on the topic soon.

  3. Great. That would be helpful. I’m always interested in learning more from folk who are more knowledgeable/experienced than I, so would find it rather useful. All the best for your hard work!

  4. Steve Miller says:

    One problem: LINQ doesn’t work with C++, and we currently have SQL code embedded in C++.

  5. Eberhard Beilharz says:

    I don’t think it is possible to get LINQ to work with Visual Studio 2005 since it requires .NET Framework 3.5 and VS05 only supports 2.0.

  6. Steve Miller says:

    Microsoft still has software online that can be downloaded for Visual Studio 2005. I downloaded it and tried it before I installed our one copy of VS 2008. I think the VS 2005 software was meant only for LINQ alpha or beta, before VS 2008 was available. Why Microsoft still has the software online for download still is beyond me.

  7. Neil Mayhew says:

    Just in case anyone out there is wondering, Firebird works well on Mac. Using a cross-platform database makes it much easier to achieve our goal of having our software work on all of the three major platforms (Windows, Linux, Mac).

  8. I see that Mono 2.0 is out now, and directly supports LINQ in C# 3.0.

  9. Anonymous says:

    It’s good that Mono 2.0 supports LINQ in C#. However, much of our legacy code is in C++. I don’t know any way around that.

  10. asava samuel says:

    Steve Miller

    I haven’t used it, but Kellerman Software has a LINQ provider for Firebird

Leave a Reply