Try this on your context:
(根据您的情况尝试以下操作:)
public class MyDatabase : DbContext
{
public MyDatabase ()
: base(ContextHelper.CreateConnection("Connection string"), true)
{
((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 180;
}
}
If you want to define the timeout in the connection string, use the Connection Timeout
parameter like in the following connection string:
(如果要在连接字符串中定义超时,请像下面的连接字符串中一样使用Connection Timeout
参数:)
<connectionStrings>
<add name="AdventureWorksEntities"
connectionString="metadata=.AdventureWorks.csdl|.AdventureWorks.ssdl|.AdventureWorks.msl;
provider=System.Data.SqlClient;provider connection string='Data Source=localhost;
Initial Catalog=AdventureWorks;Integrated Security=True;Connection Timeout=60;
multipleactiveresultsets=true'" providerName="System.Data.EntityClient" />
</connectionStrings>
Source: How to: Define the Connection String
(来源: 如何:定义连接字符串)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…