Table of Contents

Firebird Database in .NET
Resources
Installation and Setup

DDEX: Support for Visual Studio

Registry Update

Install Assembly in GAC

Machine.Config Update

Adding Firebird Support in an Application

Data Connection

Adding a Firebird data connection in MS Visual Studio 2008 Server Explorer after adding Firebird data connection in MS Visual Studio 2008

Data Source

Data-aware Controls

WPF:

<Window x:Class="FirebirdDBApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <DataGrid ItemsSource="{Binding}"></DataGrid>
    </Grid>
</Window>

C#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
 
namespace FirebirdDBApp
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
 
            // construct dataset
            datasetEzFITDB ds = new datasetEzFITDB();
 
            // use a table adapter to populate the patients table
            datasetEzFITDBTableAdapters.PATIENTTableAdapter adapt = new datasetEzFITDBTableAdapters.PATIENTTableAdapter();
            adapt.Fill(ds.PATIENT);
 
            // use the Patient table as the DataConext for this Window
            this.DataContext = ds.PATIENT.DefaultView;
        }
    }
}

Queries

Installer using InnoSetup

In [Files]] section, add global assembly cache (GAC) registration for FirebirdSql.Data.FirebirdClient.dll (one line, where {#LibDir} is where the source file is located):

Source: {#LibDir}\FirebirdClient\FirebirdSql.Data.FirebirdClient.dll; 
   DestDir: {win}\assembly; Flags: gacinstall sharedfile; 
   StrongAssemblyName: "FirebirdSql.Data.FirebirdClient, Version=2.6.0.0, Culture=neutral, 
      PublicKeyToken=3750abcc3150b00c, ProcessorArchitecture=MSIL"
Components with Data Binding

DataGridView

TextBox

Advanced Data Binding dialog

Advanced Data Binding dialog

Advanced Data Binding dialog

Advanced Data Binding dialog

BindingNavigator

ListBox

Deploying a Firebird Application

Configuration File

Add the following to the app.exe.config file (must reside in the same folder and the app.exe. See Application Settings and Configuration.ConnectionStrings for more details):

Using database server:

<?xml version="1.0"?>
<configuration>
<configSections>
</configSections>
...
<connectionStrings>
   <!--<add name="Acme.App.Database.Properties.Settings.MyAppDB_localhost"
        connectionString="character set=NONE;
            ServerType=0;
            data source=localhost;
            initial catalog=C:\Program Files\Acme\MyApp\data\mydb.gdb;
            user id=SYSDBA;
            password=masterkey;
            dialect=3"
        providerName="FirebirdSql.Data.FirebirdClient" />-->
   <add name="Acme.App.Database.Properties.Settings.MyAppDB_localhost"
        connectionString="Charset=NONE;
            ServerType=0;
            DataSource=localhost;
            Database=C:\Program Files\Acme\MyApp\data\mydb.gdb;
            User=SYSDBA;
            Password=masterkey;
            Dialect=3"
        providerName="FirebirdSql.Data.FirebirdClient" />     
</connectionStrings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
...
</configuration>

Using embedded database:

<?xml version="1.0"?>
<configuration>
<configSections>
</configSections>
...
<connectionStrings>
   <add name="Acme.App.Database.Properties.Settings.MyAppDB_localhost"
        connectionString="Charset=NONE;
            ServerType=1;
            Database=C:\Program Files\Acme\MyApp\data\mydb.gdb;
            User=SYSDBA;
            Password=masterkey;
            Dialect=3"
        providerName="FirebirdSql.Data.FirebirdClient" />
</connectionStrings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
...
</configuration>

InnoSetup script

Add the following files to distribute:

[Files]
...
;---------------------------------------------------
; Data files
;---------------------------------------------------
Source: ..\Data\mydb.gdb; DestDir: {app}\data\; Flags: onlyifdoesntexist
;---------------------------------------------------
; Database Engine files
;---------------------------------------------------
; Firebird Client
Source: {#LibDir}\FirebirdClient\FirebirdSql.Data.FirebirdClient.dll; DestDir: {win}\assembly; 
    Flags: gacinstall sharedfile; 
    StrongAssemblyName: FirebirdSql.Data.FirebirdClient, Version=2.6.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c, ProcessorArchitecture=MSIL
;Source: {#LibDir}\firebird\fbembed.dll; DestDir: {app}; DestName: gds32.dll
Source: {#LibDir}\firebird\fbembed.dll; DestDir: {app} 
; Firebird Embedded Server
Source: {#LibDir}\firebird\ib_util.dll; DestDir: {app}
Source: {#LibDir}\firebird\icudt30.dll; DestDir: {app}
Source: {#LibDir}\firebird\icuin30.dll; DestDir: {app}
Source: {#LibDir}\firebird\icuuc30.dll; DestDir: {app}
Source: {#LibDir}\firebird\firebird.msg; DestDir: {app}; Flags: ignoreversion
Source: {#LibDir}\firebird\firebird.conf; DestDir: {app}; Flags: ignoreversion
Source: {#LibDir}\firebird\udf\fbudf.dll; DestDir: {app}\udf
Source: {#LibDir}\firebird\intl\fbintl.dll; DestDir: {app}\intl; Flags: regserver noregerror
Source: {#LibDir}\firebird\intl\fbintl.conf; DestDir: {app}\intl; Flags: ignoreversion
...

Add support for creating the app.config file:

...
[Code]
//----------------------------------------------------------------------------
// global types
//----------------------------------------------------------------------------
Type
   ...
//----------------------------------------------------------------------------
// global variables
//----------------------------------------------------------------------------
var
   ...
 
//----------------------------------------------------------------------------
// function prototypes
//----------------------------------------------------------------------------
procedure DoPostInstall(); forward;
procedure CreateConfigFile(ServerName: string; DBPath: string); forward;
 
//----------------------------------------------------------------------------
// description: PostInstall custom code.  This code executes after wizard is done.
// parameters : void
// return     : void
//----------------------------------------------------------------------------
procedure DoPostInstall();
var
  ResultCode: integer;
begin
  Log('DoPostInstall(): entering...');  //debug
  //---------------------------
  // Post installation
  //---------------------------
  // unregister old DLLs
  // register DLLs
  // create registry entries
  // remove old registry entries
  // create Icon group
  ...
 
 
  // Create Config (Settings) file
  CreateConfigFile('localhost', ExpandConstant('{app}\data\mydb.gdb') );
end;
 
//----------------------------------------------------------------------------
// description: Create the config file.
// parameters : void
// return     : void
//----------------------------------------------------------------------------
procedure CreateConfigFile(ServerName: string; DBPath: string);
var
	str: array [0..15] of string;
begin
	str[0]  := '<?xml version="1.0"?>';
	str[1]  := '<configuration>';
	str[2]  := '<configSections>';
	str[3]  := '</configSections>';
	str[4]  := '<connectionStrings>';
	str[5]  := '   <add name="Acme.App.Database.Properties.Settings.MyAppDB_localhost"';
        // For Database Server:
	//str[6]  := '        connectionString="character set=NONE;ServerType=0;data source=localhost;initial catalog=C:\myapp\data\mydb.gdb;user id=SYSDBA;password=masterkey;dialect=3"';
	//str[6]  := '        connectionString="character set=NONE;ServerType=0;data source='+ ServerName + ';Database=' + DBPath + ';user id=SYSDBA;password=masterkey;dialect=3"';
        // For Embedded Database:
	str[6]  := '        connectionString="character set=NONE;ServerType=1;Database=' + DBPath + ';user id=SYSDBA;password=masterkey;dialect=3"';
	str[7]  := '        providerName="FirebirdSql.Data.FirebirdClient" />';
	str[8]  := '</connectionStrings>';
	str[9]  := '<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>';
	str[10] := '</configuration>';
 
	SaveStringsToFile(ExpandConstant('{app}\myapp.exe.config'), str, False);
end;
...