April 17, 2016

 

How to use Firebird database with a C# program - Part 1 (Preparation)

In this article and in the subsequent articles, I will show you how to write C# programs that use the embedded version of the Firebase database server. In this article, I explain how to get started.

If you know the steps, this is actually pretty easy. It's not calculus. But therein lies the rub, no?

Preparation Steps Overview

  1. Get latest version of Firebird.
  2. Start new C# project.
  3. Put relevant Firebird DLL's and .msg file in project subdirectory.
  4. Add Firebird ADO.NET provider to project.
  5. Get latest version of FlameRobin (or other database admin that works with Firebird).

1. Get latest version of Firebird.

You can download Firebird from the Firebird web site, here:

Firebird downloads

Get the embedded server. If you've already downloaded Firebird at some time, and you're using FlameRobin, here's how you can see what Firebird version you have:

Server -> Retrieve server version

You'll see something like this: "WI-V2.5.4.26856 Firebird 2.5"

2. Start new C# project.

What it says. In my case, for my own testing/usage, I've been using Visual Studio Express 2013 for Desktop and now VSE 2015 for Desktop, and just programming Console Application projects. But obviously you could use Firebird with, say, a Class Library project, or a WPF Application project.

3. Put relevant Firebird DLL's and .msg file in project subdirectory.

I've been creating a subdirectory within my project directory, and copying the relevant Firebird DLL's and ".msg" file there. Thus, for each project I have that uses the Firebird database engine (the embedded server), it is using it's own separate copies of the Firebird files. I haven't tried programming multiple projects to use the same Firebird files in a single directory, so I can't tell you anything about issues regarding concurrent program usages.

In my particular case, I just make a subdirectory called "dbengine" within my project folder, and then I copy the Firebird files into it. Here is a list of the files you need, from your download from the Firebird site:

If you want to use UDF's (user defined functions) with Firebird, then you will also need to copy the DLL "ib_util.dll". Otherwise, you don't need it. (Note that the Firebird engine will generate a log file "firebird.log" in the subdirectory, and if it doesn't see this "ib_util.dll" file it puts a warning message about not finding it in the log.)

4. Add Firebird ADO.NET provider to project.

The easiest way to do this is to use NuGet. The way this works with VSE 2015 is that in the Solution Explorer panel you right-click on the "References" entry under your project, then click on "Manage NuGet packages...". A NuGet tab window comes up in VSE. Click on the "Browse" sub-tab, and enter "FirebirdSql.Data.FirebirdClient" in the Search box. The entry for this package should show up in the search results below that (along with perhaps some other irrelevant results), and you just click on it, then click the "Install" button that will show up toward the right. This will install the Firebird ADO.NET provider package to your project.

(Obviously, if you haven't installed NuGet, you need to do this first. You can do this through Tools -> Extensions and Updates from the main menu of VSE.)

When this is installed, then in the "References" list of your project (in the Solution Explorer panel), you'll see "FirebirdSql.Data.FirebirdClient".

5. Get latest version of FlameRobin.

It's always nice to use a GUI database admin utility program to work with your database engine, and FlameRobin is kind of synonymous with Firebird. I would suppose there are alternatives (or not; I have no idea), but I loaded FlameRobin and have been using it and it has suited my needs fine, so I haven't checked into using any other database admin programs with Firebird, so I can't give you any advice in that direction.

You can download FlameRobin from the FlameRobin web site, here:

FlameRobin

As far as I know, you can't create a new database programmatically, so you have to use "isql" or a database admin program (that works with Firebird) in order to create the database(s) you'll be using with your program. Once the database is created, then everything else can be done from within your program in regard to creating tables, indexes, constraints, and so on. To create a new database with FlameRobin:

Database -> Create new database

You'll get a dialog box with these fields:

Display name:
Database path:
Authentication [method]:
User name:
Password:

The "display name" is the name used in FlameRobin, but it's the "database path" that actually specifies the path and the name of the database file. For example, "D:\prog\db\FirebirdTest\FBDB.FDB". This can, of course, be whatever you want it to be.

Miscellaneous Reference Links


Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?