I have an ASP.NET MVC application. When a new customer is created through the CustomerController, I start a new background job (using HostingEnvironment.QueueBackgroundWorkItem) to create a new Azure SqlDatabase for this customer.
I use Entity Framework Code First to create / initialize a new database. Here is the 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<CustomerDataContext, MyConfiguration>(useSuppliedContext: true)); using (var context = new CustomerDataContext(con)) { // Neither 'Connection Timeout=300' in ConnectionString nor this line helps -> TimeoutException will rise after 30-40s context.Database.CommandTimeout = 300; // create the db - this lines throws the exception after ~40s context.Database.Initialize(true); }
My problem is that I always get a TimeoutException after about 40 seconds. I think this is because Azure cannot initialize a new database in this short amount of time. Do not get me wrong: the database will be created well by Azure, but I want to wait for this point / get rid of a TimeoutException.
Edit1: I use Connection Timeout = 300 in my ConnectionString, but my application really doesn't care about that; after about 40 seconds I always encounter a SqlError.
Edit2: An exception is a SqlException . Message: Timed out. The wait period expires before the operation is completed or the server is not responding. Source: .Net SqlClient Data Provider
Edit3: Now I can say that this has nothing to do with ASP.NET/IIS. Even in the simple UnitTest method, the code above does not work.
source share