title: How to connect to Azure SQL database?
body: <p>I am trying to connect my application hosted in Azure to a database also hosted in Azure. I get an error please find the below</p>
  
  <blockquote>
    <p>"502 - Web server received an invalid response while acting as a
    gateway or proxy server."</p>
  </blockquote>
  
  <p>when the app is trying to query the database.</p>
  
  <p>Before hosting the app and the database in Azure (the app worked on localhost) my connection string to on premise SQL server database looked like this:</p>
  
  <pre><code>Data Source=DESKTOP-LCO4GKN;AttachDbFilename=|DataDirectory|BakaAppDb.mdf;Initial Catalog=BakaAppDb;Integrated Security=True
  </code></pre>
  
  <p>After migrating the database to Azure and creating a user with login I entered the connection string like this:</p>
  
  <pre><code>Server=tcp:betterorgappserver.database.windows.net;Database=BetterOrgAppDatabase_Dogfood;User ID=login1user;Password=*******;
  </code></pre>
  
  <p>The question is how should the connection string look like? I am using entity framework in my app, if that might influence its look.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>After some time I "managed" to get error specifying that the login for user failed </p>
  
  <blockquote>
    <p>Login failed for user 'login1user1'. </p>
  </blockquote>
  
  <p>This is the stack trace:</p>
  
  <pre><code>    System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal&amp; connection) +347
     System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal&amp; connection) +78
     System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal&amp; connection) +191
     System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +154
     System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +21
     System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +90
     System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +217
     System.Data.SqlClient.SqlConnection.Open() +96
     System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.&lt;Open&gt;b__36(DbConnection t, DbConnectionInterceptionContext c) +10
     and so on...
  </code></pre>
  
  <p>I guess it means I gave the privileges to the user incorrectly. So now the question is how do I add a new user with privileges to access the database?</p>
  
  <p>I did it according to this article: <a href="https://azure.microsoft.com/cs-cz/documentation/articles/sql-database-manage-logins/#granting-database-access-to-a-login" rel="nofollow">https://azure.microsoft.com/cs-cz/documentation/articles/sql-database-manage-logins/#granting-database-access-to-a-login</a></p>
  
  <p>Thanks</p>