【发布时间】:2021-02-13 23:41:41
【问题描述】:
最近我在与托管在 CentOS 8 上的 PostgreSQL 13 数据库通信时偶然发现了某些问题。我无法使用 NpgsqlConnection 类中的方法 OpenAsync() 打开连接。同步 Open() 方法可以正常工作,并允许我创建和使用连接。 我希望也许有人偶然发现了类似的问题。 提前感谢您的帮助!
示例代码:
[Fact]
public async Task TestDatabaseConnection()
{
NpgsqlLogManager.Provider = new NLogLoggingProvider();
NpgsqlLogManager.IsParameterLoggingEnabled = true;
Npgsql.NpgsqlConnection con = new Npgsql.NpgsqlConnection("Server=xxx;Database=xxx;User Id=xxx;Password=xxx");
try
{
//con.Open(); works ok
await con.OpenAsync(); //cause error
}
catch (Exception exc)
{
Console.WriteLine("test " + exc);
}
}
日志:
Opening connection...
Opening connection...
Attempting to connect to [x:x:x:x::x]:5432
Exception thrown: 'System.TimeoutException' in Npgsql.dll
Exception thrown: 'System.TimeoutException' in System.Private.CoreLib.dll
Failed to connect to [x:x:x:x::x]:5432
Exception thrown: 'System.ObjectDisposedException' in System.Net.Sockets.dll
Attempting to connect to x.x.x.x:5432
Exception thrown: 'System.TimeoutException' in Npgsql.dll
Exception thrown: 'System.ObjectDisposedException' in System.Private.CoreLib.dll
Exception thrown: 'System.TimeoutException' in System.Private.CoreLib.dll
Failed to connect to x.x.x.x:5432
Exception thrown: 'Npgsql.NpgsqlException' in Npgsql.dll
Exception thrown: 'Npgsql.NpgsqlException' in System.Private.CoreLib.dll
Exception thrown: 'Npgsql.NpgsqlException' in Npgsql.dll
Exception thrown: 'Npgsql.NpgsqlException' in System.Private.CoreLib.dll
Breaking connector
Cleaning up connector
Exception thrown: 'System.NullReferenceException' in Npgsql.dll
Object reference not set to an instance of an object.
【问题讨论】:
标签: c# postgresql centos npgsql