Failed to establish a connection to

Ricky Au 6 Reputation points
2023-01-03T04:22:40.36+00:00

Need help in connecting the Azure Postgres Database. No matter what I do, it just won't connect. The same piece of code works fine on my local database, database on VM, but not on Azure Postgres. My firewall setting seems ok because PgAdmin also works fine. User Id and Password are perfectly ok. Tried to turn off the SSL setting, but ALL documentations on Azure / Microsoft are out-dated, There is NO connection security. Nothing is working :(
My connection string looks like this:
<connectionStrings>
<add name="DefaultConnectionString" connectionString="server=somedatabase.postgres.database.azure.com;Port=5432;User Id={user id};Password={password};database={databasename};sslmode=require;" providerName="Npgsql" />
</connectionStrings>
ERROR Look like this:
[Win32Exception (0x80004005): The function requested is not supported]
[AuthenticationException: A call to SSPI failed, see inner exception.]
System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception) +1814964
System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) +121
System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) +51
System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) +52
System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) +207
System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) +139
System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) +297
System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) +51
System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) +166
System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) +573
System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation) +50
Npgsql.NpgsqlClosedState.Open(NpgsqlConnector context, Int32 timeout) +1853
[NpgsqlException (0x80004005): Failed to establish a connection to 'somedatabase.postgres.database.azure.com'.]
Npgsql.NpgsqlClosedState.Open(NpgsqlConnector context, Int32 timeout) +2026
Npgsql.NpgsqlConnector.Open() +91
Npgsql.NpgsqlConnection.Open() +328
Npgsql.NpgsqlServices.UsingPostgresDBConnection(NpgsqlConnection connection, Action1 action) +137 Npgsql.NpgsqlServices.GetDbProviderManifestToken(DbConnection connection) +99 System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +88 [ProviderIncompatibleException: The provider did not return a ProviderManifestToken string.] System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +272 System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) +27 [ProviderIncompatibleException: An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure.] System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) +89 System.Data.Entity.Infrastructure.<>c__DisplayClass1_0.<ResolveManifestToken>b__0(Tuple3 k) +32
System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) +73
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) +159
System.Data.Entity.Internal.RetryLazy2.GetValue(TInput input) +123 System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +676 System.Data.Entity.Internal.InternalContext.Initialize() +20 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +16 System.Data.Entity.Internal.Linq.InternalSet1.Initialize() +53
System.Data.Entity.Internal.Linq.InternalSet1.get_InternalContext() +15 System.Data.Entity.Infrastructure.DbQuery1.System.Linq.IQueryable.get_Provider() +38
System.Linq.Queryable.Where(IQueryable1 source, Expression1 predicate) +85
QueueOnWeb.Controllers.HomeController.LoginProcess(String name) in F:\WebProjects\QueueOnWeb\QueueOnWeb\QueueOnWeb\Controllers\HomeController.cs:369
QueueOnWeb.Controllers.HomeController.EnterName(LogonViewModel logonMode) in F:\WebProjects\QueueOnWeb\QueueOnWeb\QueueOnWeb\Controllers\HomeController.cs:327

Azure Database for PostgreSQL
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,960 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SSingh-MSFT 16,371 Reputation points Moderator
    2023-02-04T09:51:40.41+00:00

    Hi @Ricky Au ,

    You can refer to the documentation for complete TLS settings configuration in Azure PostgreSQL: how-to-tls-configurations

    Note:

    By default, Azure Database for PostgreSQL does not enforce a minimum TLS version (the setting TLSEnforcementDisabled).
    Once you enforce a minimum TLS version, you cannot later disable minimum version enforcement.

    Reference: concepts-ssl-connection-security

    Regarding C#, refer to what-version-of-tls-does-my-c-sharp-program-use
    tls
    tls-issue-unable-to-config-tls-12-with-net-472-app.html

    Please let us know if you are able to make through this. Awaiting your inputs. Thanks.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.