2009-11-24 5 views
1

검색 유형을 사용자 유형으로 구현하려고하는 검색 컨트롤이 있습니다. Linq를 사용하여 데이터베이스에 대해 쿼리를 실행합니다. 일반적으로 잘 작동하지만 사용자가 쿼리를 실제로 빠르게 입력하면 임의의 SqlException이 throw됩니다. 이것들은 내가 최근에 발견 한 두 가지 다른 오류 메시지입니다.동일한 datacontext를 사용하는 여러 쿼리가 SqlException을 throw합니다.

현재 명령에 심각한 오류가 발생했습니다. 결과가 있으면 폐기해야합니다.

리더가 닫혀있을 때 읽기를 잘못 시도했습니다.

편집 : 포함 된 코드

DataContextFactory 클래스 : 유니티

와 IDataContextFactory 등록

public DataContextFactory(IConnectionStringFactory connectionStringFactory) 
{ 
    this.dataContext = new RegionDataContext(connectionStringFactory.ConnectionString); 
} 

public DataContext Context 
{ 
    get { return this.dataContext; } 
} 

public void SaveAll() 
{ 
    this.dataContext.SubmitChanges(); 
} 

// Get connection string from Application.Current settings 
ConnectionInfo connectionInfo = Application.Current.Properties["ConnectionInfo"] as ConnectionInfo; 
// Register ConnectionStringFactory with Unity container as a Singleton 
this.container.RegisterType<IConnectionStringFactory, ConnectionStringFactory>(new ContainerControlledLifetimeManager(), 
    new InjectionConstructor(connectionInfo.ConnectionString)); 
// Register DataContextFactory with Unity container 
this.container.RegisterType<IDataContextFactory, DataContextFactory>(); 

연결 문자열 :

Data Source=.\SQLEXPRESS2008;User Instance=true;Integrated Security=true;AttachDbFilename=C:\client.mdf;MultipleActiveResultSets=true; 

저장소 클래스에서 데이터 컨텍스트 사용 :

// IDataContextFactory dependency is injected by Unity 
public CompanyRepository(IDataContextFactory dataContextFactory) 
{ 
    this.dataContextFactory = dataContextFactory; 
} 

// return List<T> of companies 
var results = this.dataContextFactory.Context.GetTable<CompanyEntity>() 
     .Join(this.dataContextFactory.Context.GetTable<RegionEntity>(), 
      c => c.regioncode, 
      r => r.regioncode, 
      (c, r) => new { c = c, r = r }) 
     .Where(t => t.c.summary_region != null) 
     .Select(t => new { Id = t.c.compcode, Company = t.c.compname, Region = t.r.regionname }).ToList(); 

작업 주위에 무엇입니까?

+0

당신은 어떻게 당신이의 DataContext를 사용하는 코드 예제를 줄 수 있습니까? – Konamiman

+0

@ Konamiman 코드 샘플이 추가되었습니다. 지금 이걸 확인해 주시겠습니까? – Raj

답변

관련 문제