SQL Server Express takes too long to wake up
I'm developing a web application using ASP.NET MVC 3 and Entity Framework Code First with SQL Server Express on the back end.
SQL Server Express falls asleep by design to conserve system resources. I'm fine with that behavior, but unfortunately the first time a page is hit after SQL Server Express has been idle for a long time, Entity Framework times out waiting for the DB to return from idle to active state.
Is there a global means to te开发者_如何转开发ll Entity Framework to wait longer for the database before throwing an Exception?
I'm not sure if DbContext API exposes any property to override default command timeout which is probably 30s for SQL Server provider. You can try to convert DbContext
to ObjectContext
and set the timeout there:
var ctx = ((IObjectContextAdapter) dbContext).ObjectContext;
ctx.CommandTimeout = 120;
精彩评论