2

我正在尝试在具有 firebird .net 提供程序(FirebirdSql.Data.FirebirdClient)的 Linux 上使用 Firebird 嵌入式 2.5(64 位)。

我的测试程序集的 FB 嵌入式设置正在使用 Windows Firebird Embedded 版本在 WinX86_64 上运行。在 Linux 上,我使用对应的 FB 嵌入式 Linux 版本将文件放置在程序集目录中:

  • libfbembed.so*
  • 火鸟.msg
  • 安全2.fdb
  • 利比库*
  • 库*

将“RootDirectory”设置为 firebird.conf 中的程序集目录。将 shell 环境变量 LD_LIBRARY_PATH 和 FIREBIRD 设置为程序集目录。

        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();

我之前做了什么:

  • 通过 mono dllmap 重定向 Firebird Clientlibrary 不起作用。通过在 C# 代码中显式设置 ClientLib 解决。
  • 在 Linux 上使用 isql 手动创建数据库是可行的。
  • 在 Linux 上通过代码创建数据库是可行的。
  • Firebird .NET 提供程序在调试模式下创建 FB_{sanitizedName}.dll 和 DynamicAssembly.dll
  • .NET 提供者真的很沉默。通过在 linux 上使用“strace mono {testAssembly.exe}”启动程序集来完成调试。
  • 如果页面大小不是 8192,则 FbConnection.CreateDatabase 在“打开 O_CREAT”(调用 FbCreateDatabase)期间因 I/O 错误而崩溃。将显式页面大小设置为 8192 可以解决此问题。

现在,我遇到了以下错误(并在这里停留了好几天......):

  • 打开一个现有的数据库文件(就像这里的代码),崩溃:

    FirebirdSql.Data.FirebirdClient.FbException:无效的数据库句柄(无活动连接)---> 无效的数据库句柄(无活动连接)

怎么了?

4

2 回答 2

0

我也遇到了这个错误。FirebirdSql.Data.FirebirdClient.FbException: invalid database handle (no active connection) 用 FB 2.5.* 和 3.0.0 的结果是一样的。还尝试使用 FB 的调试版本。日志没有帮助。

也许这里有人知道问题是什么?

于 2016-05-19T18:51:58.400 回答
0

自原始帖子以来已经3年了,我遇到了同样的问题。我没有“答案”,但我有解释。看来 SafeHandle 对象的编组并没有完全在单声道中实现。从他们关于 SafeHandle 的文档中:“请注意,“ref SafeHandles”将一个指向包含零的插槽的指针传递给 P/Invoked 方法,并在返回时使用返回的值创建一个新的 SafeHandle。“ref SafeHandles”实际上并没有得到原始 SafeHandle.handle 值。”

如果您查看 FirebirdClient 源代码,在 IFbClient 中,您会看到 P/Invoke 声明如下所示:

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

DatabaseHandle 派生自 SafeHandle,因此第二个参数是“ref SafeHandle”参数,并且存在上述问题 - 它基本上会传入零而不是实际的句柄值。

除了 (a) 改进单声道中的 SafeHandle 实现,或 (b) 重写 FirebirdClient 以避免使用 SafeHandles 之外,没有其他解决方法。

于 2019-05-09T00:37:23.333 回答