如何使用Visual C#2010连接和使用Firebird数据库嵌入式服务器

我试图将Firebird嵌入式服务器与Microsoft Visual C#2010一起使用。所以这就是我现在所做的:

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

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

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

  4. fbembed.dll文件解压缩并复制到我的应用程序目录中。

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

  6. 添加了“ 使用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#的noob,我不知道怎么做或修复它,我希望有人会帮助我。

谢谢 :)

编辑:这是我在exception中得到的:

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)位于C:\ Documents and Settings \ ermac \ My Documents \ Visual Studio 2010 \ Projects \ fbTestApp \ fbTestApp \ Form1.cs:第25行

我终于在工作6小时后找到了解决方案:)

谷歌上的大多数答案都是错误的或者是旧的。 所有人都说我只需要将fbembed.dll文件包含到我的项目中..

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

重要提示 :永远不要使用紧凑的.Net数据提供商。 因为它们仅用于普通和超级火鸟服务器。 它不适用于嵌入式服务器。

使用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 DLL放在名为Firebird的项目中的dir中。 添加了Post Build事件以复制文件。

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