Einstellung ConnectionTimeout bei der Verwendung von Entity Framework

Ich würde gerne die ConnectionTimeout auf etwas anderes als den Standardwert beträgt 15 Sekunden. Ich geerbt habe einige code, der verwendet Entity Framework und der app.config sieht wie folgt aus:

<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>

Ich bin derjenige, fügte der sectino in einem Versuch, um die Dinge zu arbeiten. Ich kann sagen, es funktioniert nicht setzen Sie einen Haltepunkt in:

var adapter = (IObjectContextAdapter) this;
var objectContext = adapter.ObjectContext;
objectContext.CommandTimeout = CommandTimeoutSeconds;
int test = objectContext.Connection.ConnectionTimeout;

test ist immer 15. Was ist Los? Kann mir jemand sagen, wie man einstellen ConnectionTimeout? Ich habe versucht, sowohl die "ConnectionTimeout" und "Connection Timeout", I. e. kein Raum vs. Raum.

Kann mir jemand helfen? Ich ziehe mir die Haare aus. Ich bin sicher, dass es eine einfache Lösung!
Dave

Zusätzliche info. Antwort auf Kommentar, hier ist mein DbContext abgeleitete Klasse...

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; }
}
  • wie erstellen Sie Ihre DbContext abgeleitete Klasse? Sie übergeben den Namen der Verbindungszeichenfolge gibt es?
  • Hallo Pawel, ich habe die DbContext-drived-Klasse in Frage. Dank für das betrachten meiner Frage.
  • Haben Sie einen Blick auf stackoverflow.com/questions/6232633/entity-framework-timeouts ?
InformationsquelleAutor Dave | 2013-08-23
Schreibe einen Kommentar