Step one: Download FireBird embedded and the .Net provider
There are numerous options available for download but I opted for the zip packages as only the assemblies and supporting files are needed.http://www.firebirdsql.org/en/server-packages/
http://www.firebirdsql.org/en/net-provider/
http://www.firebirdsql.org/manual/ufb-cs-embedded.html#ufb-cs-embedded-windows
Step two: Create your database file
There are many administrative tools available for FireBird but I opted to use FlameRobin as its free. http://www.flamerobin.org/In order to get flame robin to communicate with an embedded FireBird database there are a couple of steps required.
Copy the following FireBird embedded client files to the FlameRobin installation folder (Default C:\Program Files\FlameRobin)
fbembed.dll (Rename to fbclient.dll)
firebird.msg
icudt30.dll
icuin30.dll
icuuc30.dll
Register Server
Display name
leave hostname and port empty
Create a new database
Step 3: Create your .Net project.
Add a reference to the .Net Provider.
FirebirdSql.Data.FirebirdClient.dll
The files icudt30.dll and icuuc30.dll need to be in the build directory. Add them to the project (I added as a link as all my third party components live in a single place) and set to copy to output build directory.
Step 4: Write the code.
using System;
using FirebirdSql.Data.FirebirdClient;
namespace FirebirdClient
{
class Program
{
static void Main(string[] args)
{
var builder = new FbConnectionStringBuilder
{
UserID = "SYSDBA",
Password = "masterkey",
ServerType = FbServerType.Embedded,
Dialect = 3,
Database = @"C:\MyDatabases\MyDB1.fb"
};
using (var conn = new FbConnection(builder.ConnectionString))
{
conn.Open();
using (var cmd = new FbCommand("select * from MyTable", conn))
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine(string.Format("{0} {1}", reader["MyCol1"], reader["MyCol2"]));
}
}
}
Console.ReadLine();
}
}
}
My cousin recommended this blog and she was totally right keep up the fantastic work!
ReplyDeleteEmbedded System Projects