【问题标题】:How to connect and use Firebird db embedded server with Visual C# 2010如何使用 Visual C# 2010 连接和使用 Firebird db 嵌入式服务器
【发布时间】:2011-04-30 04:05:03
【问题描述】:

我试图将 Firebird 嵌入式服务器与 Microsoft Visual C# 2010 一起使用。 所以这是我到目前为止所做的:

  1. 已下载 Firebird .Net 数据提供程序 (Firebird Client v2.5.2)。

  2. 已下载 Firebird 嵌入式服务器 (Firebird Embedded Server v2.5.0)。

  3. 在我的项目中添加了对 FirebirdSql.Data.FirebirdClient.dll 的引用。

  4. 提取并复制 fbembed.dll 文件到我的应用程序的目录。

  5. 已将我的 FDB 文件 “TEST.FDB”添加到我的应用程序的目录中。

  6. 添加了“using FirebirdSql.Data.FirebirdClient;”语句。

到目前为止一切顺利(我想)......

现在,当我尝试使用以下代码连接到我的 FDB 文件时:

    FbConnection con = new FbConnection("User=SYSDBA;" + "Password=masterkey;" + "Database=TEST.FDB;" + "DataSource=127.0.0.1;" + "Port=3050;" + "Dialect=3;" + "Charset=UTF8;");
    try  {
             con.Open();
         }
    catch (Exception ex) 
         {
            MessageBox.Show(ex.ToString());
         }

我总是收到消息框,这意味着代码没有正确连接到我的数据库文件。 难道我做错了什么?我真的还是 C# 的菜鸟,我不知道如何做到这一点或修复它,我希望有人能帮助我。

谢谢:)

编辑:这是我在异常中得到的:

FirebirdSql.Data.FirebirdClient.FbException (0x80004005): 无法完成 对主机“127.0.0.1”的网络请求。 ---> 无法完成对主机“127.0.0.1”的网络请求。在 FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect() 在 FirebirdSql.Data.FirebirdClient.FbConnectionPool.Create() 在 FirebirdSql.Data.FirebirdClient.FbConnectionPool.CheckOut() 在 FirebirdSql.Data.FirebirdClient.FbConnection.Open() 在 fbTestApp.Form1.button1_Click(对象 发件人,EventArgs e) 在 C:\Documents 和 Settings\ermac\My Documents\Visual 工作室 2010\Projects\fbTestApp\fbTestApp\Form1.cs:行 25

【问题讨论】:

  • 收到异常时firebird是否正在运行?
  • nope..firebird 嵌入式服务器仅在我单击特定按钮时运行。

标签: c# database connection firebird firebird-.net-provider


【解决方案1】:

经过 6 个小时的工作,我终于找到了解决方案 :)

谷歌上的大多数答案要么是错误的,要么是太旧了。 他们都说我只需要将 fbembed.dll 文件包含到我的项目中..

经过我的一些调查。我发现我还需要将 firebird.msg、firebird.conf、icudt30.dll、icuin30.dll、icuuc30.dll 和 ib_util.dll 添加到我的项目 文件和 输出文件夹..

重要提示:切勿使用紧凑的 .Net 数据提供程序。因为他们只为普通和超级火鸟服务器制作了它。它不适用于嵌入式服务器。

【讨论】:

    【解决方案2】:

    嵌入 Firebird 2.5 后,我将所有这些文件复制到应用程序目录:

    aliases.conf (optional)
    fbembed.dll
    firebird.conf
    firebird.msg
    ib_util.dll
    icudt30.dll
    icuin30.dll
    icuuc30.dll
    Microsoft.VC80.CRT.manifest  : -- Not sure if this 3 files are necessary
    msvcp80.dll                  : -- but i copy them :)
    msvcr80.dll                  : -- see http://www.firebirdnews.org/?p=2248
    intl\fbintl.conf   : Without those files you can't use
    intl\fbintl.dll    : all charset and collations
    udf\*  : if you want to use pre-build UDF
    

    在连接字符串中,我指定服务器是嵌入的 serverType=1:

    User=SYSDBA;Password=masterkey;Database=E:\TEST.FDB;Dialect=3;Charset=UTF8;ServerType=1;
    

    我也忘记了 IDPLicense.txt 和 IPLicense.txt,我认为我们还必须将它们与许可证问题的申请一起分发?

    【讨论】:

    • Firebird 2.1.x 的运行时。现在,除了某些平台例外,有必要将运行时正确地安装为程序集。最小运行时由三个文件组成:msvcr80.dll、msvcp80.dll 和清单 (Microsoft.VC80.CRT.manifest)。有必要!
    【解决方案3】:

    我将 Firebird DLL 放在名为 Firebird 的项目中的一个目录中。添加了一个 Post Build 事件来复制文件。

    copy $(ProjectDir)Firebird\*.dll $(ProjectDir)$(OutDir)*.dll"
    

    【讨论】:

      【解决方案4】:

      这些是 Firebird 3.0.5 所需的文件和分发:

      - root\plugins\engine12.dll
      
      - root\intl\fbintl.conf
      - root\intl\fbintl.dll
      
      - root\fbclient.dll
      - root\icudt52.dll
      - root\icudt52l.dat
      - root\icuuc52.dll
      

      我会在我的申请开始时检查它们,以便了解可能出现的问题。

      【讨论】:

        猜你喜欢
        • 2014-10-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多