Don*_*uan 1 c# firebird firebird-3.0
从Firebird 2.5迁移到3.0后,当我尝试使用C#程序测试数据库的连接时,会出现此错误"远程接口拒绝连接".
这是测试连接的代码,当我尝试连接到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();
}
}
Run Code Online (Sandbox Code Playgroud)
对于这个答案,我假设您使用的是最近的Firebird ado.net版本(例如5.12.0.0,但至少5.0.0.0).
Firebird 3引入了线程协议加密,默认情况下是必需的.在撰写本文时,此加密不受Firebird ado.net提供程序的支持.因此,尝试连接将失败,并显示错误"远程接口拒绝连接"(错误代码335544421).
解决方案是将Firebird配置修改为仅启用(而非要求)线协议加密.要执行此操作,请编辑firebird.confFirebird服务器并将设置更改WireCrypt为WireCrypt = Enabled(如果当前以a为前缀#,请删除#),然后重新启动Firebird服务器.如果Firebird安装在Program Files中,则需要使用管理员权限运行编辑器才能正确保存文件.
请注意,在客户端和服务器之间的握手无法就某些连接和协议选项达成一致的其他情况下,也会发生此错误.
| 归档时间: |
|
| 查看次数: |
1571 次 |
| 最近记录: |