小编mmm*_*ato的帖子

实体框架数据库初始化:初始化新Azure SqlDatabase时超时

我有一个ASP.NET MVC应用程序.通过CustomerController创建新客户时,我运行新的后台任务(使用HostingEnvironment.QueueBackgroundWorkItem)为该客户创建新的Azure SqlDatabase.

我使用Entity Framework Code First来创建/初始化新数据库.这是代码:

// 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 …
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-mvc azure ef-code-first azure-sql-database

5
推荐指数
1
解决办法
2485
查看次数