c# - 连接到 Firebird 3 的 C# 程序中的 "connection rejected by remote interface"

标签 c# firebird firebird-3.0

从 Firebird 2.5 迁移到 3.0 后,当我尝试使用 C# 程序测试数据库连接时,出现“连接被远程接口(interface)拒绝”错误。

这是测试连接的代码,我在尝试连接到 firebird 2.5 数据库时使用了这段代码。

txtPassword.Properties.UseSystemPasswordChar = true;
txtHostname.Text = Properties.Settings.Default.server;
txtUsername.Text = Properties.Settings.Default.user;
txtPassword.Text = Properties.Settings.Default.pass;
txtDBPath.Text = Properties.Settings.Default.dbpath;

void Testdbconn()
{
    try
    {
        var testInMemUnicode =
            String.Format("DataSource={0};Database={1};User ID={2};Password={3}; Charset=NONE;",
                          txtHostname.Text,
                          txtHostname.Text + ":" + txtDBPath.Text.Trim(),
                          txtUsername.Text,
                          txtPassword.Text);
        var testConnParam = new FbConnection(testInMemUnicode);
        testConnParam.Open();
        XtraMessageBox.Show(@"Connection to the server is successful.", @"Data Server Test",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);

    }
    catch (Exception errorCode)
    {
        XtraMessageBox.Show(@"Error in connection: " + errorCode.Message,
                            @"Server Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Exclamation);
    }
}

class ClsConnection
{
    public static string FirebirdSQL = String.Format(
        "DataSource={0}; Database={1}; User ID={2}; Password={3}; Charset=NONE; Port=3050; Dialect=3;" +
        "Connection lifetime=15; Pooling=true; MinPoolSize=0; MaxPoolSize=2000000; Packet Size=8192; ServerType=0",
        Properties.Settings.Default.server, Properties.Settings.Default.db + ":" + Properties.Settings.Default.dbpath,
        Properties.Settings.Default.user, Properties.Settings.Default.pass);

    private static readonly string FirebirdService = FirebirdSQL;

    /// <summary>
    /// 
    /// </summary>
    public static FbConnection Firebird = new FbConnection(FirebirdService);

    /// <summary>
    /// 
    /// </summary>
    public void Openconnection()
    {
        if (Firebird.State == System.Data.ConnectionState.Open)
        {
            Firebird.Close();
        }

        Firebird.Open();
    }

    /// <summary>
    /// 
    /// </summary>
    public void Closeconnection()
    {
        Firebird.Close();
    }
}

最佳答案

对于这个答案,我假设您使用的是最新的 Firebird ado.net 版本(例如 5.12.0.0,但至少是 5.0.0.0)。

Firebird 3 引入了有线协议(protocol)加密,这是默认要求的。在撰写本文时,Firebird ado.net 提供商不支持这种加密。因此,连接尝试将失败并出现错误“连接被远程接口(interface)拒绝”(错误代码 335544421)。

解决方案是修改 Firebird 配置以仅启用而不需要有线协议(protocol)加密。为此,编辑 Firebird 服务器的 firebird.conf 并将设置 WireCrypt 更改为 WireCrypt = Enabled(如果当前前缀为 #,去掉#),重启Firebird服务器。如果 Firebird 安装在 Program Files 中,您将需要以管理员权限运行编辑器才能正确保存文件。

请注意,此错误也可能发生在客户端和服务器之间的握手无法就某些连接和协议(protocol)选项达成一致的其他情况下。

关于c# - 连接到 Firebird 3 的 C# 程序中的 "connection rejected by remote interface",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47786337/

相关文章:

firebird - 如何将整数转换为十六进制表示法?

.net - 在应用程序关闭之前,Firebird 实际上不会删除表

c# - linq2db 在 varchar 字段中查找字符串

c# - 类型 'System.Web.Mvc.MvcWebRazorHostFactory' 的表达式不能用于返回类型 'System.Web.WebPages.Razor.WebRazorHostFactory'

c# - 不着色,但 "Colorize" Sprite

sql - 使用存储函数或存储过程返回 firebird 3.0 中的表

c# - Firebird ADO.NET 4.10.0.0 数据提供程序是否可以与 Firebird 3.0 一起使用?

c# - WHERE columnName = C# 中 MySQL 查询中的数据的问题

delphi - 为什么编译器无法加载库名dbexpint.dll?

sql - 带关键字别名的 Firebird 查询