连接Heroku Postgres数据库时出现证书未知错误

4
我正在从SQL Server迁移到PostgreSQL,为了在迁移期间使我的ASP.NET应用程序能够连接到Heroku Postgres数据库并使用Entity Framework等功能,我正在构建一个临时解决方案。
到目前为止,我已经成功地从Windows的pgAdmin III连接到了数据库,但是当我从ASP.NET应用程序连接时,我遇到了这个错误:
证书未知:服务器证书未被接受。链状态:处理了一个证书链,但以不被信任的根证书终止。指定的主机名不存在于证书中。
我对Heroku仍然相当陌生,但是无法理解为什么我可以使用与ASP.NET应用程序相同的设置从pgAdmin连接,但在应用程序本身中却无法工作。
完整的堆栈跟踪:
[ClientAlertException: 证书未知:服务器证书未被接受。 链状态:处理了一个证书链,但在不被信任的信任提供程序中终止了根证书。指定的主机名不在证书中。]
TlsClientStream.TlsClientStream.SendAlertFatal(AlertDescription description, String message) +44
TlsClientStream.TlsClientStream.ParseCertificateMessage(Byte[] buf, Int32& pos) +1359
TlsClientStream.TlsClientStream.TraverseHandshakeMessages() +415
TlsClientStream.TlsClientStream.GetInitialHandshakeMessages(Boolean allowApplicationData) +336
TlsClientStream.TlsClientStream.PerformInitialHandshake(String hostName, X509CertificateCollection clientCertificates, RemoteCertificateValidationCallback remoteCertificateValidationCallback, Boolean checkCertificateRevocation) +198

[IOException: TlsClientStream.ClientAlertException: 证书未知:服务器证书未被接受。 链状态:处理了一个证书链,但在不被信任的信任提供程序中终止了根证书。指定的主机名不在证书中。 at TlsClientStream.TlsClientStream.SendAlertFatal(AlertDescription description, String message) at TlsClientStream.TlsClientStream.ParseCertificateMessage(Byte[] buf, Int32& pos) at TlsClientStream.TlsClientStream.TraverseHandshakeMessages() at TlsClientStream.TlsClientStream.GetInitialHandshakeMessages(Boolean allowApplicationData) at TlsClientStream.TlsClientStream.PerformInitialHandshake(String hostName, X509CertificateCollection clientCertificates, RemoteCertificateValidationCallback remoteCertificateValidationCallback, Boolean checkCertificateRevocation)]
TlsClientStream.TlsClientStream.PerformInitialHandshake(String hostName, X509CertificateCollection clientCertificates, RemoteCertificateValidationCallback remoteCertificateValidationCallback, Boolean checkCertificateRevocation) +289
Npgsql.NpgsqlConnector.RawOpen(NpgsqlTimeout timeout) +1372
Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout) +314
Npgsql.NpgsqlConnection.OpenInternal() +461
Npgsql.NpgsqlConnection.Open() +4
Npgsql.NpgsqlServices.UsingPostgresDBConnection(NpgsqlConnection connection, Action`1 action) +162
Npgsql.NpgsqlServices.GetDbProviderManifestToken(DbConnection connection) +99
System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +87

[ProviderIncompatibleException: 提供程序没有返回 ProviderManifestToken 字符串。]
System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +271
System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) +27

[ProviderIncompatibleException: 访问数据库时出错。这通常意味着连接到数据库失败。请检查连接字符串是否正确,以及使用适当的 DbContext 构造函数来指定它或在应用程序的配置文件中找到它。有关 DbContext 和连接的信息,请参见 http://go.microsoft.com/fwlink/?LinkId=386386。有关故障的详细信息,请参见内部异常。]
System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) +89
System.Data.Entity.Infrastructure.<>c__DisplayClass1.b__0(Tuple`3 k) +31
System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +62
System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.ResolveManifestToken(DbConnection connection) +251
System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest) +56
System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +43
System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +62
System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) +123
System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +627 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +18

1个回答

10

尝试在连接字符串中使用"Trust Server Certificate=true",版本为Npgsql 3.1.5。

Server=[servername];Port=[port];User Id=[username];Password=[password];Database=[databasename];sslmode=Require;Trust Server Certificate=true

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接