2

I'm trying to get Firebird-embedded 2.5 (64bit) on Linux with firebird .net provider (FirebirdSql.Data.FirebirdClient) working.

The FB embedded setup for my Test assembly is working on WinX86_64 with the Windows Firebird Embedded version. On Linux I use the coresponding FB embedded Linux version placed files in the assembly directory:

  • libfbembed.so*
  • firebird.msg
  • security2.fdb
  • libicu*
  • libib*

Set the "RootDirectory" to assembly directory in the firebird.conf. Set the shell environment variables LD_LIBRARY_PATH and FIREBIRD to to assembly directory.

        FbConnectionStringBuilder conn = new FbConnectionStringBuilder();            
        conn.Database = @"/home/dev/firebirdTest/1stDB.FDB";
        conn.ServerType = FbServerType.Embedded;
        conn.UserID = "SYSDBA";
        conn.Password = "masterkey"; 
        conn.Charset = "UTF8";
        conn.DataSource = "localhost";
        conn.ClientLibrary = "libfbembed.so";
        string connStr = conn.ConnectionString;
        var dbcon = new FbConnection(connStr);
        FbConnection.CreateDatabase(connStr, pageSize: 8192, forcedWrites: true, overwrite: false);
        dbcon = new FbConnection(connStr);
        dbcon.Open();

what I did before:

  • Redirecting the Firebird Clientlibrary by mono dllmap doesn't work. Solved by explicit setting the ClientLib in C# code.
  • manually creating a Database with isql on Linux works.
  • creating a Database by code on Linux works.
  • the Firebird .NET provider creates in debug mode the FB_{sanitizedName}.dll and DynamicAssembly.dll
  • the .NET provider is really silent. Debugging was done by starting the assembly with "strace mono {testAssembly.exe}" on linux.
  • FbConnection.CreateDatabase crashes with I/O error during "open O_CREAT" (calling FbCreateDatabase), if pagesize is not 8192. Setting explicit pagesize to 8192 solves this.

Now, I run in following errors ( and stuck here for days...):

  • Opening an existing Databasefile (like in the code here), crashes with:

    FirebirdSql.Data.FirebirdClient.FbException: invalid database handle (no active connection) ---> invalid database handle (no active connection)

What's going wrong?

okionka
  • 21
  • 2
  • I don't think Firebird Embedded will work with the Firebird .net Provider on Mono. I assume (but I might be wrong) it uses some Windows specifics there. You might want to ask this question on the Firebird .net provider mailinglist as well. – Mark Rotteveel May 10 '16 at 14:06

2 Answers2

0

I've stuck with this error too. FirebirdSql.Data.FirebirdClient.FbException: invalid database handle (no active connection) Tried with FB 2.5.* and 3.0.0 results are the same. Also tried using debug builds of FB. Logs did not help.

Maybe somebody here knows what the problem is?

Pavel Melnikov
  • 965
  • 9
  • 8
0

It's 3 years since the original post, and I've run into the same problem. I don't have an "answer" but I do have an explanation. It appears the marshalling of SafeHandle objects isn't fully implemented in mono. From their documentation on SafeHandle: "Notice that “ref SafeHandles” pass a pointer to a slot containing zero to P/Invoked methods, and on return the a new SafeHandle is created with the returned value. “ref SafeHandles” do not actually get the original SafeHandle.handle value."

If you look into the FirebirdClient source, in IFbClient, you'll see the P/Invoke declarations look like:

    IntPtr isc_detach_database(
        [In, Out] IntPtr[] statusVector,
        [MarshalAs(UnmanagedType.I4)] ref DatabaseHandle dbHandle);

DatabaseHandle is derived from SafeHandle, so the second argument is a "ref SafeHandle" argument, and suffers from the problem noted above - it will basically pass in a zero rather than the actual handle value.

There is no fix other than to (a) improve the SafeHandle implementation in mono, or (b) rewrite FirebirdClient to avoid the use of SafeHandles.