3

I'm trying to get the Firebird Embedded working in a simple .NET Core (2.1) console application scenario.

My project file looks like this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="6.4.0" />
  </ItemGroup>

</Project>

and Program.cs like this:

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

namespace Playground
{
    class Program
    {
        static void Main(string[] args)
        {
            var workingDir = Directory.GetCurrentDirectory();
            var dbPath = Path.Combine(workingDir, "Database.fdb");

            var connString = 
                new FbConnectionStringBuilder
                {
                    ClientLibrary = "libfbclient.dylib",
                    ServerType = FbServerType.Embedded,
                    UserID = "sysdba",
                    Database = dbPath
                }
                .ToString();

            Console.WriteLine(connString);

            FbConnection.CreateDatabase(connString, false);

            var sql =
                @"
                CREATE TABLE my_table (
                    id int NOT NULL PRIMARY KEY,
                    name varchar(20) NOT NULL
                );
                ";

            using (var conn = new FbConnection(connString))
            using (var cmd = new FbCommand(sql, conn))
            {
                conn.Open();
                cmd.ExecuteNonQuery();
            }
        }
    }
}

After building the project (simply by dotnet build) I copy following files from the binary package for Mac (Firebird-3.0.4-33054-lipo-x86_64.pkg) to the output directory (./bin/Debug/netcoreapp2.1):

libfbclient.dylib
libib_util.dylib
libicudata.dylib
libicui18n.dylib
libicuuc.dylib
plugins (directory)
    libEngine12.dylib

Upon running the app (dotnet MyApp.dll) I get an exception:

Unhandled Exception: FirebirdSql.Data.FirebirdClient.FbException: Unable to complete network request to host "localhost".
Failed to establish a connection. ---> FirebirdSql.Data.Common.IscException: Unable to complete network request to host "localhost".
Failed to establish a connection.
   at FirebirdSql.Data.Client.Native.FesDatabase.ProcessStatusVector(IntPtr[] statusVector) in C:\Users\Jiri\Documents\devel\NETProvider\working\Provider\src\FirebirdSql.Data.FirebirdClient\Client\Native\FesDatabase.cs:line 332
   at FirebirdSql.Data.Client.Native.FesDatabase.CreateDatabase(DatabaseParameterBuffer dpb, String dataSource, Int32 port, String database, Byte[] cryptKey) in C:\Users\Jiri\Documents\devel\NETProvider\working\Provider\src\FirebirdSql.Data.FirebirdClient\Client\Native\FesDatabase.cs:line 171
   at FirebirdSql.Data.FirebirdClient.FbConnectionInternal.CreateDatabase(DatabaseParameterBuffer dpb) in C:\Users\Jiri\Documents\devel\NETProvider\working\Provider\src\FirebirdSql.Data.FirebirdClient\FirebirdClient\FbConnectionInternal.cs:line 125
   at FirebirdSql.Data.FirebirdClient.FbConnection.CreateDatabaseImpl(String connectionString, Int32 pageSize, Boolean forcedWrites, Boolean overwrite) in C:\Users\Jiri\Documents\devel\NETProvider\working\Provider\src\FirebirdSql.Data.FirebirdClient\FirebirdClient\FbConnection.cs:line 101
   --- End of inner exception stack trace ---
   at FirebirdSql.Data.FirebirdClient.FbConnection.CreateDatabaseImpl(String connectionString, Int32 pageSize, Boolean forcedWrites, Boolean overwrite) in C:\Users\Jiri\Documents\devel\NETProvider\working\Provider\src\FirebirdSql.Data.FirebirdClient\FirebirdClient\FbConnection.cs:line 106
   at Playground.Program.Main(String[] args) in /Users/anil/Temp/Playground/Program.cs:line 24

I've used Firebird successfully in many scenarios (network server, embedded) and with different technologies (Delphi, .NET, .NET Core) for last 15 years, albeit only on Windows.

Is anyone able to assist with this issue or point me to the relevant place where I could RTFM and solve it myself?

Anil
  • 991
  • 1
  • 13
  • 23
  • What version of MacOS are you trying to run this on? – Ed Mendez Jan 15 '19 at 03:31
  • @EdMendez 10.13.6 (High Sierra) – Anil Jan 15 '19 at 08:10
  • 1
    I had some progress with the issue here: https://groups.google.com/forum/#!topic/firebird-net-provider/0-L7EXP_DJs Apparently, due to the library paths, embedded engine doesn't get loaded and is trying to connect to `localhost` instead. Patching of `dylib`s didn't help. After installing Firebird (which has put the libs in the expected place) and granting permissions on the `/tmp/firebird` directory it worked, but that's far from frictionless and isolated deployment scenario that I want to achieve (which is possible on windows). – Anil Jan 15 '19 at 08:12

0 Answers0