2

I'm having a simple ASP Web API 2 application which is deployed to an Azure Web App. It is using an SQL database also hosted on Azure. The DbContext is set using Publish dialog as in the following image so I trust VS tools, and I'm assuming that the connection string is correctly set: (example followed can be found here)

enter image description here

The connection string is set on Web.config

<connectionStrings>
    <add name="DefaultConnection" 
         connectionString="..." 
         providerName="System.Data.SqlClient"/>
</connectionStrings>

and used in the ctor of IdentityDbContext:

public ApplicationDbContext() : base("DefaultConnection")

When the API project is debugged locally it can access the production db without a problem, but once it is deployed it can't access it anymore. Below are the exceptions (sent back to postman). There were some other answers on SO about similar issues but I didn't succeed so far in following them.

[Win32Exception (0x80004005): No such host is known]

[SqlException (0x80131904): A network-related or instance-specific 
error occurred while establishing a connection to SQL Server. The 
server was not found or was not accessible. Verify that the instance
name is correct and that SQL Server is configured to allow remote
connections. (provider: TCP Provider, error: 0 - No such host is known.)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +92
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +285
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover, SqlAuthenticationMethod authType) +372
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +172

[ProviderIncompatibleException: The provider did not return a ProviderManifestToken string.]
System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +271
System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) +33

[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) +246
System.Data.Entity.Infrastructure.<>c__DisplayClass1.<ResolveManifestToken>b__0(Tuple`3 k) +32
System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +72
System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.ResolveManifestToken(DbConnection connection) +251
4
  • 1
    Are you transforming config files depending on build config? Commented Sep 14, 2015 at 14:16
  • 1
    No, I disabled them in order to debug this issue. Commented Sep 14, 2015 at 14:18
  • 1
    If you can verify that the connection string is correct in your production environment, your problem is probably that the production DB is unavailable from the network location you are trying to access it? Are you sure about the DNS, you have no entries in your hosts file pointing to the DB? Commented Sep 14, 2015 at 14:21
  • 1
    Both WebApp and Sql Database are hosted and managed from Azure portal. Should there be granted some kind of permissions? Commented Sep 14, 2015 at 14:23

1 Answer 1

1

Verify that your LIVE connection string is correct

Go to http://myWebApp.scm.azurewebsites.net and choose Debug Console > PowerShell. Then run this to view your LIVE connection string.

cd site/wwwroot
$xml = [xml](Get-Content Web.config)
$connStrings = $xml.SelectSingleNode("configuration/connectionStrings") 
$connStrings.InnerXml

Verify that your firewall rules are correct

Go to http://portal.azure.com, open your database server (BROWSE ALL > Sql servers > myServer), and choose Settings. Under Firewall ensure that Allow access to Azure services is ON.

A picture of the new azure portal Firewall settings area.

You can also do this from the Azure PowerShell like this:

Get-AzureAccount                                # sign-in to your account
Get-AzureResource -ResourceGroupName mvp2015 `
    -ResourceName mvp2015 `
    -ResourceType Microsoft.Sql/servers/firewallrules `
    -OutputObjectFormat New

If you see a rule named AllowAllWindowsAzureIps then you're already configured properly.

Check your Web App configuration

You might be overriding the Web.config in the Web App configuration.

You can check this at portal.azure.com > Browse All > MyAppName > Settings > Application settings > Connection strings. If you have one there named DefaultConnection it will override the Web.config connection string.

You can also check this at myappname.scm.azurewebsites.net > Environment > Connection Strings. Ensure that the DefaultConnection listed there, if at all, is what you want it to be.

Kudu Connection Strings

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for tips. Unfortunately the string connection is correct and the permissions are set.
Indeed, there is an old DefaultConnection in myappname.scm.azurewebsites.net connection strings. Which Web App configuration does set this connection string?
Usually you can find connection string overrides in portal.azure.com > Browse All > MyAppName > Settings > Application settings > Connection strings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.