如何在Visual C# 2010中连接和使用Firebird db嵌入式服务器

13

我试图在 Microsoft Visual C# 2010 中使用 Firebird 嵌入式服务器。以下是我到目前为止所做的事情:

  1. 下载了 Firebird .Net 数据提供程序 (Firebird 客户端 v2.5.2)。

  2. 下载了 Firebird 嵌入式服务器 (Firebird 嵌入式服务器 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(Object sender, EventArgs e) in C:\Documents and Settings\ermac\My Documents\Visual Studio 2010\Projects\fbTestApp\fbTestApp\Form1.cs:line 25


你在收到异常时,Firebird是否正在运行? - Pieter van Ginkel
不对,Firebird嵌入式服务器只有在我点击特定按钮时才会运行。 - Desolator
4个回答

10

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

在谷歌上的大部分答案都是错误的或者很老旧。它们都说我只需要将fbembed.dll文件包含到我的项目中即可。

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

重要提示:永远不要使用紧凑型.NET数据提供程序。因为它们只适用于普通和超级Firebird服务器。它不能与嵌入式服务器一起使用。


6

使用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)。必要! - amstegraf

2

我把Firebird动态链接库放在名为Firebird的项目目录中。添加了一个Post Build事件来复制这些文件。

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

0

以下是 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

我在应用程序开始时检查它们,以便我可以通知可能出现的问题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接