2

After migrating from Firebird 2.5 to 3.0 this error "connection rejected by remote interface" shows up when I try to test the connection of the database using C# program.

Here is the code for testing the connection, I use this code when I try to connect to the firebird 2.5 database.

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();
    }
}
4

1 回答 1

7

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

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

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

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

于 2017-12-13T12:04:34.270 回答