Embedded Firebird Server

5 posts, 1 answers
  1. Tsybulnikov
    Tsybulnikov avatar
    7 posts
    Member since:
    May 2012

    Posted 07 Aug 2014 Link to this post

    Can I use Data Access ORM with Firebird without necessary to install Firebird Provider .Net?

    Where I should specify FirebirdSql.Data.FirebirdClient.dll ?
  2. Tsybulnikov
    Tsybulnikov avatar
    7 posts
    Member since:
    May 2012

    Posted 07 Aug 2014 in reply to Tsybulnikov Link to this post

    _connectionString = @"character set=WIN1251;initial catalog=D:\TestApp\bin\x86\Release\POST.FDB;clientlibrary=D:\TestApp\Binaries\fbembed.dll;password=masterkey;user id=SYSDBA;data source=AbonDb;server type=1";
     var dataContext = new AbonDataEntitiesModel(_connectionString);
    var s = dataContext.Employees.FirstOrDefault();

    I use Firebird Embbded Server and specified it in connection string like above. But if I don't install FirebirdProvider I will take next exception:

    System.IO.FileLoadException: Cannot load file or assembly "FirebirdSql.Data.FirebirdClient, Version=4.2.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c" (Exception HRESULT: 0x80131040)
  3. DevCraft banner
  4. Answer
    Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 08 Aug 2014 Link to this post

    Hello Oleg,


    as far as I know using the embedded Firebird database should be possible, but you will need to make the Firebird driver assemblies known and available. You should be able to do so by adding a

      <system.data>
        <DbProviderFactories>
          <add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient, Version=3.0.2.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c" />
        </DbProviderFactories>
      </system.data>

    configuration file entry to you app.config. This tells the .NET runtime what to use when looking for a ADO driver for firebird. To use the embedded version, you will need to specify that via the ServerType=1 in the connection string (see https://www.connectionstrings.com/firebird/ )
    Don't forget to put the FirebirdSql.Data.FirebirdClient assembly into you assembly folder!

    Regards,
    Thomas
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  5. Tsybulnikov
    Tsybulnikov avatar
    7 posts
    Member since:
    May 2012

    Posted 08 Aug 2014 in reply to Thomas Link to this post

    Yes. It's approach work for application (exe), but it doesn't work with assembly. I found next trick to do this:

    var assembly = Assembly.GetAssembly(typeof(FirebirdClientFactory));
    var assemblyName = assembly.GetName();
     
    var dataSet = ConfigurationManager.GetSection("system.data") as System.Data.DataSet;
    var table = dataSet.Tables[0];
     
    foreach (DataRow row in table.Rows.Cast<DataRow>().ToList())
    {
        if (row[2].ToString() == assembly.GetName().Name)
        {
            table.Rows.Remove(row);
        }
    }
     
    table.Rows.Add("FirebirdSql Data Provider"
            , ".Net Framework Data Provider for FirebirdSql"
            , assembly.GetName().Name//"FirebirdSql.Data.FirebirdClient"
            , string.Format(@"FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, {0}",
            assembly.FullName
            )
    );
  6. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 13 Aug 2014 Link to this post

    Hi Oleg,

    thanks for sharing this code with us. This is the programmatic way of modifying the runtime configuration to know about a certain ADO database driver.

    Regards,
    Thomas
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
Back to Top
DevCraft banner