在.NET中连接到嵌入有C#的Firebird 3的问题 [英] Problem connecting to Firebird 3 embedded with C# in .NET

查看:355
本文介绍了在.NET中连接到嵌入有C#的Firebird 3的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从.NET项目连接到Firebird 3嵌入式数据库.我已将Firebird的所有文件复制到应用程序的执行目录.我使用了以下连接字符串生成器:

I am trying to connect to Firebird 3 embedded database from a .NET project. I have copied all the files of Firebird to the executing directory of the application. I have used the following connection string builder:

            var builder = new FbConnectionStringBuilder()
            {
                UserID = v1,
                Password = v2,
                Database = v3,
                ServerType = FbServerType.Embedded,
                Charset = "UTF8",
                ClientLibrary = "fbclient.dll" 
            };

但是我收到以下连接错误

However I get the following connection error

FirebirdSql.Data.FirebirdClient.FbException(0x80004005):
无法完成主机"xnet://Global \ FIREBIRD"的网络请求.

FirebirdSql.Data.FirebirdClient.FbException (0x80004005):
Unable to complete network request to host "xnet://Global\FIREBIRD".

无法完成网络请求以托管"xnet://Global \ FIREBIRD".

Unable to complete network request to host "xnet://Global\FIREBIRD".

在FirebirdSql.Data.FirebirdClient.FbConnectionPoolManager.Pool.CreateNewConnectionIfPossibleImpl(FbConnectionString connectionString)
在FirebirdSql.Data.FirebirdClient.FbConnectionPoolManager.Pool.GetConnection(FbConnection所有者)
在FirebirdSql.Data.FirebirdClient.FbConnection.Open()
在DZApp.LoginForm.CheckPassword(String v1,String v2,String v3)在C:\ Users \ DZ \ Desktop \ DZApp \ DZApp \ LoginForm.cs:line 89

at FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()
at FirebirdSql.Data.FirebirdClient.FbConnectionPoolManager.Pool.CreateNewConnectionIfPossibleImpl(FbConnectionString connectionString)
at FirebirdSql.Data.FirebirdClient.FbConnectionPoolManager.Pool.GetConnection(FbConnection owner)
at FirebirdSql.Data.FirebirdClient.FbConnection.Open()
at DZApp.LoginForm.CheckPassword(String v1, String v2, String v3) in C:\Users\DZ\Desktop\DZApp\DZApp\LoginForm.cs:line 89

我知道该密码不是必需的,因此已将其删除,但是它不起作用,这可能是问题所在吗?

I know that the password is not necessary and have removed it but it doesn't work, what could be the problem?

推荐答案

当我不使用fbclient.dll来访问Firebird Embedded时,我可以用一个简单的应用程序重现此错误,而是在搜索路径上加载fbclient.dll(例如,如果应用程序是32位,则在C:\ Windows \ System32或C:\ Windows \ SysWoW64中).

I am able to reproduce this error with a simple application when it does not use the fbclient.dll with access to Firebird Embedded, but instead loads a fbclient.dll on the search path (eg in C:\Windows\System32 or C:\Windows\SysWoW64 if the application is 32 bits).

在这种模式下,fbclient尝试通过XNET协议(即通过xnet://Global\FIREBIRD)建立与Firebird实例的本地"连接.当没有Firebird运行时,此操作将失败.

In that mode, fbclient tries to establish a 'local' connection to a Firebird instance through the XNET protocol (that is through xnet://Global\FIREBIRD). When no Firebird is running, this then fails.

在尝试重现此问题时,我发现以下情况可能触发此情况:

In my attempts to reproduce this, I have found the following conditions can trigger this:

  • 只有fbclient.dll部署在应用程序的文件夹中,而没有其余的Firebird Embedded:

  • Only fbclient.dll is deployed in the folder of the application without the rest of Firebird Embedded:

fbclient尝试通过XNET创建本地连接,但失败.

fbclient attempts to create a local connection through XNET, which fails.

不存在嵌入式引擎(engine12.dll)或在错误的位置.如果fbclient.dll位于C:\path\to\firebird\fbclient.dll,则engine12.dll应该位于C:\path\to\firebird\plugins\engine12.dll

The embedded engine (engine12.dll) is not present or in the wrong location. If fbclient.dll is at C:\path\to\firebird\fbclient.dll, then engine12.dll should be at C:\path\to\firebird\plugins\engine12.dll

fbclient尝试通过XNET创建本地连接,但失败.

fbclient attempts to create a local connection through XNET, which fails.

这是上一项的明确示例.

This is an explicit example of the previous item.

fbclient.dll 部署在应用程序的文件夹中:

fbclient.dll is not deployed in the folder of the application:

fbclient(例如,在Windows \ System32或SysWoW64中),它尝试通过XNET创建本地连接,但失败.

fbclient on the path (eg in Windows\System32 or SysWoW64) is used instead, which attempts to create a local connection through XNET, which fails.

这种情况将在路径上没有适当位的fbclient.dll时触发DllNotFoundException.

This case will trigger a DllNotFoundException instead when there is no fbclient.dll of the appropriate bitness on the path.

fbclient.dll +嵌入式Firebird与应用程序(例如x86或具有64位Firebird的AnyCPU应用程序或具有32位Firebird的x64应用程序)具有不同的位数

fbclient.dll + Firebird embedded have different bitness from application (eg x86 or AnyCPU application with a 64 bit Firebird, or a x64 application with a 32 bit Firebird)

使用路径上具有适当位数的fbclient(例如,在Windows \ System32或SysWoW64中),尝试通过XNET创建本地连接,但失败.

fbclient with appropriate bitness on the path (eg in Windows\System32 or SysWoW64) is used instead, which attempts to create a local connection through XNET, which fails.

这种情况可能会在路径上没有适当位的fbclient.dll时触发BadImageFormatException.

This case may trigger a BadImageFormatException instead when there is no fbclient.dll of the appropriate bitness on the path.

顺便说一句:在这种情况下,如果Firebird实例正在运行,则会导致错误连接丢失到数据库" ,这可能是因为Firebird ADO.net提供程序未提供Firebird Embedded不需要密码(尽管我尚未验证),而本地连接则不需要.

As an aside: under these conditions, if a Firebird instance is running, it will result in an error "connection lost to database" instead, probably because the Firebird ADO.net Provider does not supply a password as Firebird Embedded does not need it (although I haven't verified that), while a local connection does.

简而言之:

  • 确保Firebird Embedded已与您的应用程序一起正确部署,并且
  • 确保Firebird Embedded对您的应用程序具有正确的位数.

  • ensure that Firebird Embedded is correctly deployed together with your application, and
  • ensure that Firebird Embedded has the correct bitness for your application.

这意味着,对于C#x86或AnyCPU:32位,对于x64:64位.或对于AnyCPU,请在程序属性">为平台构建"目标中禁用首选32位":AnyCPU以确保加载64位DLL.

That means, for C# x86 or AnyCPU: 32 bit, for x64: 64 bit. Or for AnyCPU, disable 'Prefer 32-bit' in the Program Properties > Build for Platform target: AnyCPU to ensure it loads 64 bit DLLs instead.

运行有效的Firebird 3 Embedded所需的文件为(引自博客文章我写过有关使用Java的Firebird Embedded的文章:

The files necessary for a working Firebird 3 Embedded deployment are (quoted from a blogpost I wrote about using Firebird Embedded from Java):

fb
|--intl
|  |--fbintl.conf
|  \--fbintl.dll
|--plugins
|  |--engine12.dll
|  |--fbtrace.dll
|  |--legacy_auth.dll
|  |--legacy_usermanager.dll
|  |--srp.dll
|  |--udr_engine.conf
|  \--udr_engine.dll
|--fbclient.dll
|--icudt52.dll
|--icudt52l.dll
|--icuin52.dll
\--icuuc52.dll

fb文件夹是普通Firebird的精简版本 安装. plugins中的某些DLL可能是 不需要文件夹(这可能需要调整firebird.conf), 错误记录表明可能有必要包括 ib_util.dll也是如此,但是示例程序在没有它的情况下也可以工作.如果 您需要其他配置,那么您可以添加一个 firebird.conf.

The fb folder is a trimmed down version of a normal Firebird installation. It is possible that some of the DLLs in the plugins folder are not necessary (this may require tweaking firebird.conf), and error logging suggests it might be necessary to include ib_util.dll as well, but the example program works without it. If you need additional configuration, then you can include a firebird.conf.

与引用的树中显示的相反,在plugins文件夹中实际上只需要engine12.dll.

Contrary to what is shown in the quoted tree, only engine12.dll is really required in the plugins folder.

这篇关于在.NET中连接到嵌入有C#的Firebird 3的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆