如何通过 Visual C# 2010 连接和使用 Firebird db 嵌入式服务器
我试图将 Firebird 嵌入式服务器与 Microsoft Visual C# 2010 一起使用。 所以这是我到目前为止所做的:
下载Firebird .Net Data Provider (Firebird 客户端 v2.5.2)。
已下载Firebird嵌入式服务器(Firebird 嵌入式服务器 v2.5.0)。
向我的项目添加了对 FirebirdSql.Data.FirebirdClient.dll 的引用。
将fbembed.dll 文件提取并复制到我的应用程序的目录。
将我的 FDB 文件“TEST.FDB”添加到我的应用程序的目录。
添加了“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());
}
我总是收到消息框,这意味着代码未正确连接到我的 DB 文件。 我做错了什么吗?我真的还是 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 中 和设置\ermac\我的文档\Visual 工作室 2010\项目\fbTestApp\fbTestApp\Form1.cs:行 25
I was trying to use Firebird embedded server with Microsoft Visual C# 2010.
so here is what I done till now:
Downloaded Firebird .Net Data Provider (Firebird Client v2.5.2).
Downloaded Firebird Embedded server (Firebird Embedded Server v2.5.0).
Added a reference to FirebirdSql.Data.FirebirdClient.dll to my project.
Extracted and Copied fbembed.dll file to my application's directory.
Added my FDB file "TEST.FDB" to my application's directory.
Added "using FirebirdSql.Data.FirebirdClient;" statement.
So far so good (I suppose)...
Now when I try to connect to my FDB file using the following code:
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());
}
I always get the messagebox which means the code is not connecting to my DB file properly.
am I doing something wrong? I'm really still noob with C# and I have no idea how to do this or fix it and I hope someone will help me with this.
thanks :)
EDIT: here is what I get in the exception:
FirebirdSql.Data.FirebirdClient.FbException
(0x80004005): Unable to complete
network request to host "127.0.0.1".
---> Unable to complete network request to host "127.0.0.1". at
FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()
at
FirebirdSql.Data.FirebirdClient.FbConnectionPool.Create()
at
FirebirdSql.Data.FirebirdClient.FbConnectionPool.CheckOut()
at
FirebirdSql.Data.FirebirdClient.FbConnection.Open()
at
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
经过 6 个小时的工作,我终于找到了解决方案:)
谷歌上的大多数答案要么是错误的,要么太旧了。
他们都说我只需要将 fbembed.dll 文件包含到我的项目中..
经过我做了一些调查。我发现我还需要将 firebird.msg、firebird.conf、icudt30.dll、icuin30.dll、icuuc30.dll 和 ib_util.dll 添加到我的项目 文件并保存到输出文件夹。
重要通知:切勿使用紧凑的 .Net 数据提供程序。因为他们只为普通和超级火鸟服务器制作。它不适用于嵌入式服务器。
I finally I found the solution after 6 hours of work :)
most of answers on google are either wrong or so old.
all of them say that I only need to include fbembed.dll file to my project..
after some investigations I made. I found that I also need to add firebird.msg, firebird.conf, icudt30.dll, icuin30.dll, icuuc30.dll and ib_util.dll to my project files and to the output folder..
important notice: never use compact .Net data provider. because they made it for Normal and super firebird servers only. it won't work with embedded servers.
嵌入 Firebird 2.5 后,我将所有这些文件复制到应用程序目录中:
在连接字符串中,我指定服务器是嵌入的 serverType=1:
我还忘记了 IDPLicense.txt 和 IPLicense.txt,我认为我们还必须分发他们与申请牌照有关吗?
With Firebird 2.5 embedded, I copy all this files to the application directory :
In the connection string, I specify that the server is embedded wih serverType=1:
I forgot also IDPLicense.txt and IPLicense.txt, I think we have to also distribute them with the application for license issue ?
我将 Firebird DLL 放在名为 Firebird 的项目中的目录中。添加了构建后事件来复制文件。
I put the Firebird DLLs in a dir in the project called Firebird. Added a Post Build event to copy the files.
这些是 Firebird 3.0.5 所需的文件和发行版:
我在应用程序开始时检查它们,以便我可以告知可能出现的问题。
These are the files and distribution you need for Firebird 3.0.5:
I check them out at the beginning of my application so I can inform what can go wrong.