简体   繁体   English

无法将 postgresql db 连接到我的 netcore Web 项目(DigitalOcean Cloud)

[英]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我的连接字符串

  • (1) From my test db (working): (1)从我的测试数据库(工作):

optionsBuilder.UseNpgsql( "Server=my-server;Port=5432;Database=mydb; User Id=myuser;Password=mypsw;");

  • (2) From digital ocean db (not working): (2)来自数字海洋数据库(不工作):

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.

相关问题 Thingsboard无法连接到外部数据库Postgresql Google Cloud - Thingsboard cannot connect to external DB postgresql google cloud 使用 Cloud SQL PostgreSQL DB 在 Cloud Run 上的 Django 应用程序出错 - 无法连接到数据库 - Error with Django application on Cloud Run using Cloud SQL PostgreSQL DB - cannot connect to database 无法连接到heroku PostgreSQL数据库 - Cannot connect to heroku PostgreSQL db 无法在Play框架中连接到Postgresql DB - Cannot connect to Postgresql DB in Play framework 无法在Nodejs中连接本地PostgreSQL DB - Cannot connect local PostgreSQL DB in Nodejs 无法使用 DBeaver 连接到本地 postgresql 数据库 - Cannot connect to local postgresql DB using DBeaver 如何从 ASP.NET 核心 web Z8A5DA52ED125772A8AAZE 调用存储在 DigitalOcean 中的 postgresql db? - How can I call a postgresql db stored in DigitalOcean from ASP.NET Core web api? 如何从 CircleCI 连接到 DigitalOcean 上的 PostgreSQL 集群? - How to connect to PostgreSQL cluster on DigitalOcean from CircleCI? OpenShift Nextgen无法将Postgresql连接到Java项目 - OpenShift Nextgen cannot connect postgresql to java project 通过 docker-compose 连接 Spring Cloud DataFlow 和 Postgresql-db - connect Spring Cloud DataFlow and Postgresql-db by docker-compose
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM