title: Entity Framework Database Initialization: Timeout when initializing new Azure SqlDatabase
body: <p>I have an ASP.NET MVC application. When a new customer is created via <em>CustomerController</em> I run a new background task (using <em>HostingEnvironment.QueueBackgroundWorkItem</em>) to create a new Azure SqlDatabase for that customer.</p>
  
  <p>I use Entity Framework Code First to create/initialize the new database. Here's the code:</p>
  
  <pre><code>// My ConnectionString
  var con = "...";
  
  // Initialization strategy: create db and execute all Migrations
  // MyConfiguration is just a DbMigrationsConfiguration with AutomaticMigrationsEnabled = true
  Database.SetInitializer(strategy: new MigrateDatabaseToLatestVersion&lt;CustomerDataContext, MyConfiguration&gt;(useSuppliedContext: true));
  
  using (var context = new CustomerDataContext(con))
  {
      // Neither 'Connection Timeout=300' in ConnectionString nor this line helps -&gt; TimeoutException will rise after 30-40s
      context.Database.CommandTimeout = 300;
  
      // create the db - this lines throws the exception after ~40s
      context.Database.Initialize(true);
  }
  </code></pre>
  
  <p>My Problem is that I always get a <em>TimeoutException</em> after about 40secs. I think that happens because Azure cannot initialize the new database within this short period of time. Don't get me wrong: The database will be created well by Azure but I want to wait for that point / get rid of the <em>TimeoutException</em>.</p>
  
  <p><strong>Edit1:</strong>
  I'm using <em>Connection Timeout=300</em> in my ConnectionString but my app doesn't really care about that; after about 40s I'm always running into an SqlError.</p>
  
  <p><strong>Edit2:</strong>
  The exception that raises is an <strong>SqlException</strong>. <em>Message</em>: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. <em>Source</em>: .Net SqlClient Data Provider</p>
  
  <p><strong>Edit3:</strong>
  I can confim now that this has nothing to do with ASP.NET/IIS. Even in a simple UnitTest method the code above fails.</p>