title: Cannot connect to SQL Azure from local machine
body: <p>I have made a simple SQL generator XAML application based on Fluent NHibernate that allows me to generate the DDL to run onto database. With a local MySQL setup it works fine.</p>
  
  <p>I want now to run it onto SQL Azure.</p>
  
  <ul>
  <li>I have created a website that will host the NH application on Management Portal. Check!</li>
  <li>I have created the database used by the NH application. Check!</li>
  <li>I have set up a firewall rule to allow my IP address to connect to SQL Azure. Check!</li>
  <li>I have tried to connect to Azure's official DB management portal and logged in with my credentials. Check!</li>
  <li>I have tried to run the NHibernate schema generator with the correct connection string (double-checked the password) but I had an error. Boom!</li>
  </ul>
  
  <p>The error(anonymised) is the following</p>
  
  <pre><code>---------------------------
  
  ---------------------------
  Cannot open database "[MyDb]" requested by the login. The login failed.
  
  Login failed for user 'mydblogin'.
  
  This session has been assigned a tracing ID of '{{guid}}'.  Provide this tracing ID to customer support when you need assistance.
  ---------------------------
  OK   
  ---------------------------
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>PersistenceConfigurer persistenceConfigurer = MsSqlConfiguration.MsSql2008
      .Dialect&lt;MsSqlAzure2008Dialect&gt;()
      .Driver&lt;SqlClientDriver&gt;()
      .FormatSql()
      .ShowSql()
      .ConnectionString(connectionString);
  
  FluentConfiguration fc = Fluently.Configure()
      .Database(persistenceConfigurer)
      .ExposeConfiguration(
          cfg =&gt; cfg.SetProperty("hbm2ddl.keywords", "auto-quote")
                      .SetProperty("hbm2ddl.auto", "none"))
      .Mappings(
      m =&gt; m.FluentMappings.AddFromAssemblyOf&lt;NHibernateFactory&gt;()
      .Conventions.AddFromAssemblyOf&lt;NHibernateFactory&gt;());
  Configuration ret = fc.BuildConfiguration();
  SchemaMetadataUpdater.QuoteTableAndColumns(ret);
  </code></pre>
  
  <p>Connection string (obfuscated)</p>
  
  <pre><code>Server=tcp:dbhost.database.windows.net,1433;Database=[MyDb];User ID=login@dbhost;Password=password;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;
  </code></pre>
  
  <p>Exception is <code>System.Data.SqlClient.SqlException (0x80131904)</code></p>
  
  <p>Stack trace</p>
  
  <pre><code>   in System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
     in System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
     in System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean&amp; dataReady)
     in System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
     in System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
     in System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
     in System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
     in System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
     in System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions)
     in System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
     in System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
     in System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions userOptions)
     in System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionOptions userOptions)
     in System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal&amp; connection)
     in System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal&amp; connection)
     in System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal&amp; connection)
     in System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
     in System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
     in System.Data.SqlClient.SqlConnection.Open()
     in NHibernate.Connection.DriverConnectionProvider.GetConnection()
     in NHibernate.Tool.hbm2ddl.ManagedProviderConnectionHelper.Prepare()
     in NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper)
     in NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(IDictionary`2 cfgProperties)
     in NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.QuoteTableAndColumns(Configuration configuration)
     in HbmSchemaExporter.NHibernateManager.BuildNHConfig(String connectionString, DbType dbType, Dialect&amp; requiredDialect)
     in HbmSchemaExporter.NHibernateManager.GenerateSql(MainWindowViewModel viewModel)
     in HbmSchemaExporter.MainWindow.btnGenerateSql_Click(Object sender, RoutedEventArgs e)
  </code></pre>
  
  <p>The question is obvious: what's wrong in code or configuration? I am sure that password is typed correctly, I have copied the rest of the connection string and replaced password placeholder. I have set up firewall rules and AFAIK without firewall rules you can't use <a href="https://yourdbhost.database.windows.net/" rel="nofollow">https://yourdbhost.database.windows.net/</a></p>