Chciałbym ustawić ConnectionTimeout na coś innego niż domyślny, który wynosi 15 sekund. I zostały odziedziczone niektóre kod, który używa EntityFramework i app.config wygląda następująco:Ustawianie ConnectionTimeout przy użyciu EntityFramework
<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>
ja jestem tym, który dodał ten sectino próbując dostać rzeczy działa. Mogę powiedzieć, że nie działa ustawianie punktu przerwania na:
var adapter = (IObjectContextAdapter) this;
var objectContext = adapter.ObjectContext;
objectContext.CommandTimeout = CommandTimeoutSeconds;
int test = objectContext.Connection.ConnectionTimeout;
test jest zawsze 15. Co się dzieje? Czy ktoś może mi powiedzieć, jak ustawić ConnectionTimeout? Próbowałem zarówno "ConnectionTimeout" i "Connection Timeout" tj. brak przestrzeni a przestrzeń.
Czy ktoś może mi pomóc? Wyciągam włosy. Jestem pewien, że to prosta łatka! Dave
Dodatkowe informacje. W odpowiedzi na komentarz, tutaj jest mój DbContext pochodzi klasa ...
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; }
}
Jak utworzyć klasę pochodną DbContext? Czy przekazujesz tam nazwę połączenia? – Pawel
Cześć Pawel, Wstawiłem klasę z napisem DbContext w pytaniu. Dziękuję za spojrzenie na moje pytanie. – Dave
Czy obejrzałeś http://stackoverflow.com/questions/6232633/entity-framework-timeouts? –