连接到Heroku Postgres数据库

时间:2016-06-23 15:40:47

标签: asp.net postgresql ssl heroku heroku-postgres

所以我正在从SQL Server迁移到PostgreSQL,我正在为迁移期构建一个临时解决方案,以允许我的ASP.NET应用程序连接到我的Heroku Postgres数据库并使用Entity Framework等。

到目前为止,我已经设法从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(布尔   allowApplicationData)+336
  TlsClientStream.TlsClientStream.PerformInitialHandshake(字符串   hostName,X509CertificateCollection clientCertificates,   RemoteCertificateValidationCallback   remoteCertificateValidationCallback,Boolean   checkCertificateRevocation)+199

     

[IOException:TlsClientStream.ClientAlertException:   CertificateUnknown:不接受服务器证书。连锁状态:   已处理证书链,但在根证书中终止   信任提供商不信任。 。指定的主机名   证书中没有。在   TlsClientStream.TlsClientStream.SendAlertFatal(AlertDescription   description,String message)at   TlsClientStream.TlsClientStream.ParseCertificateMessage(Byte [] buf,   INT32和放大器; pos)at   TlsClientStream.TlsClientStream.TraverseHandshakeMessages()at   TlsClientStream.TlsClientStream.GetInitialHandshakeMessages(布尔   allowApplicationData)at   TlsClientStream.TlsClientStream.PerformInitialHandshake(字符串   hostName,X509CertificateCollection clientCertificates,   RemoteCertificateValidationCallback   remoteCertificateValidationCallback,Boolean   checkCertificateRevocation)]
  TlsClientStream.TlsClientStream.PerformInitialHandshake(字符串   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   连接,动作`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   连接)+271
  System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices   providerServices,DbConnection连接)+27

     

[ProviderIncompatibleException:访问时出错   数据库。这通常意味着与数据库的连接   失败。检查连接字符串是否正确并且是   适当的DbContext构造函数用于指定或查找   它在应用程序的配置文件中。看到   http://go.microsoft.com/fwlink/?LinkId=386386了解有关的信息   DbContext和连接。有关详细信息,请参阅内部异常   失败]
  System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices   providerServices,DbConnection连接)+89
  System.Data.Entity.Infrastructure<> c__DisplayClass1.b__0(元组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
  System.Data.Entity.Internal.Linq.InternalSet 1.Initialize() +53
System.Data.Entity.Internal.Linq.InternalSet
1.get_InternalContext()   +15 System.Data.Entity.Infrastructure.DbQuery 1.System.Linq.IQueryable.get_Provider() +38 System.Linq.Queryable.Where(IQueryable 1个源,表达式1 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.CallBeginDelegate(AsyncCallback)   callback,Object callbackState)+14
  System.Web.Mvc.Async.WrappedAsyncResultBase 1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeActionMethodWithFilters(ControllerContext controllerContext, IList
1个过滤器,ActionDescriptor actionDescriptor,   IDictionary的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.CallBeginDelegate(的AsyncCallback   callback,Object callbackState)+14
  System.Web.Mvc.Async.WrappedAsyncResultBase 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.CallBeginDelegate(的AsyncCallback   callback,Object callbackState)+30
  System.Web.Mvc.Async.WrappedAsyncResultBase 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.CallBeginDelegate(的AsyncCallback   callback,Object callbackState)+20
  System.Web.Mvc.Async.WrappedAsyncResultBase 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
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&amp; completedSynchronously)+155

1 个答案:

答案 0 :(得分: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