ConnectionTimeoutをデフォルト以外の15秒に設定したいとします。私はEntityFrameworkを使用するいくつかのコードを継承しているとのapp.configは、次のようになります。EntityFrameworkを使用する場合のConnectionTimeoutの設定
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS; Integrated Security=True; ConnectionTimeout=30; MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; ConnectionTimeout=30; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
私が働いて物事を取得しようとする試みでsectinoを追加したものをです。何が起こっているかを常に15
var adapter = (IObjectContextAdapter) this;
var objectContext = adapter.ObjectContext;
objectContext.CommandTimeout = CommandTimeoutSeconds;
int test = objectContext.Connection.ConnectionTimeout;
テストされています。私が言うことができる、にブレークポイントを設定することが動作しないのですか? ConnectionTimeoutの設定方法を教えてもらえますか?私は "ConnectionTimeout"と "Connection Timeout"の両方を試しました。スペース対スペースなし。
誰かが私を助けることができますか?私は私の髪を引っ張っています。私はそれが簡単な修正だと確信しています! デーブ
追加情報コメントに応じて、ここに私のDbContext派生クラスは...
public class SessionDataContext : DbContext
{
// Command timeout (seconds)
private const int CommandTimeoutSeconds = 30;
/// <summary>
/// Constructor that takes db name.
/// The connection string and db itself is configured in the this project's app.config file
/// </summary>
/// <param name="dbName"></param>
public SessionDataContext(string dbName) : base(dbName)
{
Database.SetInitializer(new SessionDataContextInitializer());
// Set timeout (based on code from http://stackoverflow.com/questions/6232633/entity-framework-timeouts)
var adapter = (IObjectContextAdapter) this;
var objectContext = adapter.ObjectContext;
objectContext.CommandTimeout = CommandTimeoutSeconds;
int test = objectContext.Connection.ConnectionTimeout;
}
/// <summary>
/// Session table's records
/// </summary>
public DbSet<Session> Sessions { get; set; }
/// <summary>
/// SessionType table's records
/// </summary>
public DbSet<SessionType> SessionTypes { get; set; }
}
DbContext派生クラスを作成するにはどうすればよいですか?そこに接続文字列名を渡していますか? – Pawel
こんにちはPawel、私はDbContext drivedクラスを質問に入れました。私の質問を見てくれてありがとう。 – Dave
http://stackoverflow.com/questions/6232633/entity-framework-timeoutsをご覧くださいか? –