连接到Heroku Postgres数据库时出现CertificateUnknown错误

bar*_*e.m 3 asp.net postgresql ssl heroku heroku-postgres

所以,我在从SQL Server迁移到PostgreSQL的中间,我建设迁移期间的临时解决方案,让我的ASP.NET应用程序连接到我的Heroku Postgres数据库,并利用实体框架等.

到目前为止,我已经设法从pgAdmin III连接到数据库的Windows没有问题,但是当从ASP.NET应用程序连接时,我收到此错误:

CertificateUnknown:不接受服务器证书.链状态:已处理证书链,但终止于信任提供程序不信任的根证书..证书中不存在指定的主机名.

我仍然是heroku的新手,但是为什么我可以使用与我的ASP.NET应用程序相同的设置从pgAdmin连接它没有意义,但它在应用程序本身中不起作用.

完整堆栈跟踪:

[ClientAlertException:CertificateUnknown:不接受服务器证书.链状态:已处理证书链,但终止于信任提供程序不信任的根证书..证书中不存在指定的主机名.]
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:CertificateUnknown:不接受服务器证书.链状态:已处理证书链,但终止于信任提供程序不信任的根证书..证书中不存在指定的主机名.在TlsClientStream.TlsClientStream.SendAlertFatal(AlertDescription描述,字符串消息)在TlsClientStream.TlsClientStream.ParseCertificateMessage(字节[] buf中,的Int32&POS)在TlsClientStream.TlsClientStream.TraverseHandshakeMessages()在TlsClientStream.TlsClientStream.GetInitialHandshakeMessages(布尔allowApplicationData)在TlsClientStream.TlsClientStream .PerformInitialHandshake(字符串主机名,X509CertificateCollection clientCertificates,RemoteCertificateValidationCallback remoteCertificateValidationCallback,布尔checkCertificateRevocation)]
TlsClientStream.TlsClientStream.PerformInitialHandshake(字符串主机名,X509CertificateCollection clientCertificates,RemoteCertificateValidationCallback remoteCertificateValidationCallback,布尔checkCertificateRevocation)289
Npgsql.NpgsqlConnector.RawOpen(NpgsqlTimeout超时)1372
Npgsql.NpgsqlConnector .开(NpgsqlTimeout超时)314
Npgsql.NpgsqlConnection.OpenInternal()461
Npgsql.NpgsqlConnection.Open()4
Npgsql的 .NpgsqlServices.UsingPostgresDBConnection(NpgsqlConnection连接,Action`1动作)+162
Npgsql.NpgsqlServices.GetDbProviderManifestToken(DbConnection连接)+99
System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection连接)+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 2.GetOrAdd( TKey键,Func 2.GetValue(TInput输入)+123 System.Data.Entity.Internal.LazyInternalContext.InitializeContext()+ 627 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)+18 System.Data.Entity .Internal.Linq.InternalSet 1.get_InternalContext()15 System.Data.Entity.Infrastructure.DbQuery 1源,表达1.CallBeginDelegate(AsyncCallback的回调,对象callbackState)14个 System.Web.Mvc.Async.WrappedAsyncResultBase 1个过滤器, ActionDescriptor actionDescriptor,IDictionary的1.CallBeginDelegate(AsyncCallback的回调,对象callbackState)+14 System.Web.Mvc.Async.WrappedAsyncResultBase 1.CallBeginDelegate(AsyncCallback的回调,对象callbackState)+30 的System.Web .Mvc.Async.WrappedAsyncResultBase 1.CallBeginDelegate(AsyncCallback callback,Object callbackState)+20 System.Web.Mvc.Async.WrappedAsyncResultBase 1.CallBeginDelegate(AsyncCallback callback,Object callbackState)+30 System.Web.Mvc.Async.WrappedAsyncResultBase`1 .Begin(AsyncCallback回调,对象状态,Int32超时)+128 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext,AsyncCallback回调,对象状态) +384 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext,AsyncCallback回调) ,对象状态)+48 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context,AsyncCallback cb,Object extraData)+16 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +103 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&completedSynchronously)+1553 k) +31
System.Collections.Concurrent.ConcurrentDictionary
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


1.Initialize() +53
System.Data.Entity.Internal.Linq.InternalSet
1.System.Linq.IQueryable.get_Provider() +38 System.Linq.Queryable.Where(IQueryable1 predicate) +83
Saleboat.Logic.MeetingLogic.CheckMeetingFilter.OnActionExecuting(ActionExecutingContext filterContext) in C:\Users\Michael\Documents\Visual Studio 2013\Projects\Saleboat\project-saleboat\Saleboat\Logic\MeetingLogic\CheckMeetingFilter.cs:22 System.Web.Mvc.Async.AsyncInvocationWithFilters.InvokeActionMethodFilterAsynchronouslyRecursive(Int32 filterIndex) +176
System.Web.Mvc.Async.AsyncInvocationWithFilters.InvokeActionMethodFilterAsynchronouslyRecursive(Int32 filterIndex) +644
System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__31(AsyncCallback asyncCallback, Object asyncState) +58
System.Web.Mvc.Async.WrappedAsyncResult

1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeActionMethodWithFilters(ControllerContext controllerContext, IList
2 parameters, AsyncCallback callback, Object state) +197
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__19(AsyncCallback asyncCallback, Object asyncState) +743
System.Web.Mvc.Async.WrappedAsyncResult

1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) +343
System.Web.Mvc.Controller.<BeginExecuteCore>b__1c(AsyncCallback asyncCallback, Object asyncState, ExecuteCoreState innerState) +25
System.Web.Mvc.Async.WrappedAsyncVoid

1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +465
System.Web.Mvc.Controller.<BeginExecute>b__14(AsyncCallback asyncCallback, Object callbackState, Controller controller) +18
System.Web.Mvc.Async.WrappedAsyncVoid

1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +374
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +16
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(AsyncCallback asyncCallback, Object asyncState, ProcessRequestState innerState) +52 System.Web.Mvc.Async.WrappedAsyncVoid





小智 6

使用Npgsql 3.1.5尝试在连接字符串中使用"Trust Server Certificate = true".连接字符串示例:

Server=[servername];Port=[port];User Id=[username];Password=[password];Database=[databasename];sslmode=Require;Trust Server Certificate=true
Run Code Online (Sandbox Code Playgroud)