[英]Cannot connect postgresql db to my netcore web project (DigitalOcean Cloud)
I want to use my postgresql db from digital ocean in my webpage.我想在我的网页中使用来自数字海洋的 postgresql 数据库。 Before i create this db, i have a free one for test and is working fine, but this new its not working.
在我创建这个数据库之前,我有一个免费的用于测试并且工作正常,但是这个新的它不起作用。 I can connect from pgadmin to the db without problem.
我可以毫无问题地从 pgadmin 连接到数据库。
My web project is a net core 2.1.我的网络项目是一个网络核心 2.1。
My connection strings我的连接字符串
optionsBuilder.UseNpgsql( "Server=my-server;Port=5432;Database=mydb; User Id=myuser;Password=mypsw;");
optionsBuilder.UseNpgsql("Server=myserver;Port=25060;Database=defaultdb; User Id=doadmin;Password=mypsw;SslMode=Require");
If i use the (1) connection it works perfect, but when i change to (2) connection throw me the error message.如果我使用 (1) 连接它可以完美运行,但是当我更改为 (2) 连接时会向我抛出错误消息。 This is the error message:
这是错误消息:
“The remote certificate is invalid according to the validation procedure.” “根据验证程序,远程证书无效。”
My web its certificated with Let's Encrypt, certbot.我的网站通过 Let's Encrypt、certbot 认证。
Tell me if you need more info.如果您需要更多信息,请告诉我。
I found the solution, my problem was the ssl certificate, letsencrypt its a self-signed certificate and with sslmode=require, the connection fail.我找到了解决方案,我的问题是 ssl 证书,让其加密为自签名证书,并且使用 sslmode=require,连接失败。 So you have to add this parameter
Trust Server Certificate=true
.所以你必须添加这个参数
Trust Server Certificate=true
。
optionsBuilder.UseNpgsql("Server=myserver;Port=25060;Database=defaultdb; User Id=doadmin;Password=mypsw;SslMode=Require;Trust Server Certificate=true");
Source: https://www.npgsql.org/doc/security.html#encryption-ssltls来源: https : //www.npgsql.org/doc/security.html#encryption-ssltls
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.