title: Asp Web Api deployed db connection
body: <p>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 <code>DbContext</code> 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 <a href="https://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-rest-service-aspnet-api-sql-database/" rel="nofollow noreferrer">here</a>)</p>
  
  <p><a href="https://i.stack.imgur.com/zftyE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zftyE.png" alt="enter image description here"></a></p>
  
  <p>The connection string is set on Web.config</p>
  
  <pre><code>&lt;connectionStrings&gt;
      &lt;add name="DefaultConnection" 
           connectionString="..." 
           providerName="System.Data.SqlClient"/&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>and used in the <code>ctor</code> of <code>IdentityDbContext</code>:</p>
  
  <pre><code>public ApplicationDbContext() : base("DefaultConnection")
  </code></pre>
  
  <p>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.</p>
  
  <pre><code>[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.&lt;&gt;c__DisplayClass1.&lt;ResolveManifestToken&gt;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
  </code></pre>