我在从Azure网站连接我的DB时遇到了一个错误,它是在虚拟机角色(我有SQL虚拟机角色)。VM Role和Azure Website都在West zone。我面临着以下问题:

SqlException (0x80131904):成功建立了与服务器的连接,但是在登录过程中发生了错误。(提供者:SSL提供者,错误:0 -证书链是由一个不受信任的机构颁发的。)]

我可以使用SSMS连接到我的DB。虚拟机角色的1433端口是开放的。 我的连接有什么问题?


当前回答

短的通知。如果您正在使用AWS RDS,您可以从truststore.pki.rds.amazonaws.com获得证书。有关特定链接的详细信息可以在本文档中找到:https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html。

只需下载适当的证书并将其安装到您的主机上。

其他回答

我决定添加另一个答案,因为这篇文章会作为这个错误的第一个谷歌结果弹出。

如果你在2022年1月之后得到这个错误,可能是在从System.Data.SqlClient迁移到Microsoft.Data.SqlClient之后,或者只是将Microsoft.Data.SqlClient更新到4.0.0或更高版本之后,这是因为MS引入了一个破坏性的更改:

https://learn.microsoft.com/sql/connect/ado-net/introduction-microsoft-data-sqlclient-namespace?view=sql-server-ver15#breaking-changes-in-40

Breaking changes in 4.0 Changed Encrypt connection string property to be true by default. The default value of the Encrypt connection setting has been changed from false to true. With the growing use of cloud databases and the need to ensure those connections are secure, it's time for this backwards-compatibility-breaking change. Ensure connections fail when encryption is required In scenarios where client encryption libraries were disabled or unavailable, it was possible for unencrypted connections to be made when Encrypt was set to true or the server required encryption.

此更改是在2021年8月的SqlClient拉取请求中进行的,其中有关于此更改的额外讨论。

快速解决方法是在连接字符串中添加Encrypt=False。

我在实体框架迁移中得到了这个消息。我能够与Win Auth连接到Sql Server,并手动创建表。但EF行不通。这个连接字符串终于工作了

Server=MyServerName;Database=MyDbName;Trusted_Connection=SSPI;Encrypt=false;TrustServerCertificate=true

如果你使用EF Core 7,微软官方文档中解释了一个突破性的变化 https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-7.0/breaking-changes#encrypt-defaults-to-true-for-sql-server-connections

我在试图运行剖析器时遇到了这个错误,即使我的连接已经检查了信任服务器证书,并且我在高级部分添加了TrustServerCertificate=True。我改为以管理员身份运行SSMS实例,分析器启动时没有问题。(我以前发现,即使是本地连接也需要很长时间才能连接,以管理员身份运行也会有所帮助)。

"ConnectionStrings": {
    "DefaultConnection": "Server=DESKTOP-O5SR0H0\\SQLEXPRESS;Database=myDataBase;Trusted_Connection=True;TrustServerCertificate=True;"
  }
}