我不知道为什么,但是每当我试图连接到我的数据库时,这种情况就会发生
SocketException: An existing connection was forcibly closed by the remote host.
我在connection.json中使用connection.json和Npgsql,如下所示
{
"server": "localhost",
"port": "5432",
"database": "Postgres2",
"userID": "postgres",
"password": "admin"
}
我的代码看起来像这样
string serverConfigLocation = "Data/conn.json";
async void Start()
{
var cS = new ConnectionString();
if(File.Exists(serverConfigLocation))
{
using (StreamReader r = new StreamReader(serverConfigLocation))
{
var json = r.ReadToEnd();
cS = ConnectionString.FromJson(json);
}
}
System.Net.ServicePointManager.SecurityProtocol =
System.Net.SecurityProtocolType.Tls |
System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;
var connectionString = "Host=" + cS.server + ";Username=" + cS.userID + ";Password="
+ cS.password + ";Database=" + cS.database;
await using var conn = new NpgsqlConnection(connectionString);
await conn.OpenAsync();
}
发布于 2022-09-25 20:06:06
完成后,我重新安装了我的PgAdmin和PostgreSql,它就像一种魅力。但我不知道那是怎么发生的。
https://stackoverflow.com/questions/73741440
复制相似问题