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을 추가 한 하나입니다. 중단 점을 설정하는 것이 작동하지 않는다고 말할 수 있습니다.
var adapter = (IObjectContextAdapter) this;
var objectContext = adapter.ObjectContext;
objectContext.CommandTimeout = CommandTimeoutSeconds;
int test = objectContext.Connection.ConnectionTimeout;
테스트는 항상 15입니다. 진행 상황은 무엇입니까? 누군가 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를 보셨습니까? –