title: Timeout expired. The timeout period elapsed prior to completion of the operation on Azure sql
body: <p>I need to create one sql database on windows azure on the global.asax application start event, however I got this error:</p>
  
  <pre><code>Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.  This failure occurred while attempting to connect to the routing destination. The duration spent while attempting to connect to the original server was - [Pre-Login] initialization=296; handshake=324; [Login] initialization=0; authentication=1; [Post-Login] complete=94;
  </code></pre>
  
  <p>My code is as follows:</p>
  
  <pre><code>   private void SetupSSM() {
              SqlConnectionStringBuilder connStrBldr = new SqlConnectionStringBuilder
              {
                  UserID = SettingsHelper.AzureUsernamedb,
                  Password = SettingsHelper.AzurePasswordDb,
                  ApplicationName = SettingsHelper.AzureApplicationName,
                  DataSource = SettingsHelper.AzureSqlServer
              };
  
              bool created=DbUtils.CreateDatabaseIfNotExists(connStrBldr.ConnectionString, SettingsHelper.Azureshardmapmgrdb);
              if(created)
              {
                  Sharding sharding = new Sharding(SettingsHelper.AzureSqlServer, SettingsHelper.Azureshardmapmgrdb, connStrBldr.ConnectionString);
              }
          }
  
  
  
    public static bool CreateDatabaseIfNotExists(string connectionString, string databaseName)
          {
              using (SqlConnection conn = new SqlConnection(connectionString))
              {
                  conn.Open();
  
                  SqlCommand cmd = new SqlCommand(
                      string.Format("SELECT * FROM sys.databases WHERE [name]=\'{0:S}\'", databaseName),
                      conn);
  
                  if (cmd.ExecuteScalar() == null)
                  {
                      SqlCommand cmd2 = new SqlCommand(
                          string.Format("CREATE DATABASE [{0:S}];", databaseName),
                          conn);
  
                      cmd2.ExecuteNonQuery();
  
                      return true;
                  }
                  else
                      return false;
              }
          }
  </code></pre>
  
  <p>How can I increase the timeout>? is it sql timeout or a web request timeout due to sql not responding?</p>