2016-07-06 4 views
-1

Npgsql을 사용하는 일부 쿼리에서 임의의 오류가 발생합니다. 여기 Npgsql nhibernate 57014 문 시간 초과로 인한 명령문 취소

는 스택 추적입니다 :

at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Loader.cs:line 1597 
    at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Loader.cs:line 1497 
    at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Loader.cs:line 1487 
    at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 1955 
    at NHibernate.Impl.CriteriaImpl.List(IList results) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\CriteriaImpl.cs:line 265 
    at NHibernate.Impl.CriteriaImpl.List[T]() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\CriteriaImpl.cs:line 276 
    at LAVASPORT.DAO.MigrarCadeteDAO.findByCompania(Compania compania, String conexion, DateTime fechainicial, DateTime fechafinal) in D:\Aplicaciones\LavaSport\LAVASPORT\DAO\MigrarCadeteDAO.cs:line 125 

그리고 여기에 메시지

InnerException = {"57014: canceling statement due to statement timeout"} 

나는이 예외 모든 시간, 하루에 단 1 개 또는 2 번을받지 못했습니다에게 있습니다. 대부분의 예외를 보내는 쿼리는 대용량 쿼리입니다. 여기

쿼리입니다 :

public IList<Cadete> findByCompania(Compania compania, String conexion,DateTime fechainicial,DateTime fechafinal) 
     { 
      try 
      { 
       DateTime fechaini = new DateTime(fechainicial.Year, fechainicial.Month, fechainicial.Day); 
       DateTime fechafin = new DateTime(fechafinal.Year, fechafinal.Month, fechafinal.Day); 
       var nhConfig = new Configuration().Configure(conexion); 
       var sessionFactory = nhConfig.BuildSessionFactory(); 
       var session = sessionFactory.OpenSession(); 
       session.BeginTransaction(); 
       var query = session.CreateCriteria<Cadete>(); 
       query.CreateAlias("compania", "compania"); 
       query.Add(Restrictions.Eq("compania.id", compania.id)) 
        .Add(Restrictions.Lt("fechaIngreso", fechafin)) 
        .Add(Restrictions.Ge("fechaIngreso",fechaini)); 
       IList<Cadete> cadetes = query.List<Cadete>(); 
       return cadetes; 
      } 
      catch (Exception ex) 
      { 
       MessageBox.Show("Error : " + ex.Message); 
      } 
      return null; 
     } 

이 내 NHibernate에 구성 및 내 웹 설정 파일이다 : 나는 1000 개 이상에 제한 시간을 늘리면

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" > 
    <session-factory name="LAVASPORT"> 
    <property name="connection.driver_class">NHibernate.Driver.NpgsqlDriver</property> 
    <property name="connection.connection_string"> 
     Server=localhost;database=LAVASPORT;user id=postgres;password=admin;MaxPoolSize=500;TimeOut=1000; 
    </property> 
    <property name="dialect">NHibernate.Dialect.PostgreSQLDialect</property> 
    <property name="show_sql">true</property> 
    <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property> 
    <mapping assembly="LAVASPORT"/> 
    </session-factory> 
</hibernate-configuration> 

, 나는 연결마다에 오류가 발생할 수 시각.

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/> 
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"></section> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections> 
    <startup> 
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/> 
    </startup> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> 
     <parameters> 
     <parameter value="v11.0"/> 
     </parameters> 
    </defaultConnectionFactory> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/> 
    </providers> 
    </entityFramework> 
    <system.transactions> 
    <defaultSettings timeout="10:00:00" /> 
    </system.transactions> 
</configuration> 

정말 도움이됩니다.

답변

0

첫째, Timeout 연결 문자열 파라미터 타임 아웃 (즉, NpgsqlConnection.Open()) 대신 명령 실행 제한 시간보다 연결을 관리하는 것을 도와. Defaul 명령 실행 제한 시간은 Command Timeout 연결 문자열 매개 변수를 통해 관리됩니다.

그 외에도, 귀하의 명령이 단순히 시간 초과되는 것처럼 보입니다. 기본 명령 시간 초과가 30 초이기 때문에 쿼리, 데이터베이스 인덱스 또는 기타 심각한 성능 문제가있는 것으로 보입니다. 당신은 신중하게 NHibernate에 의해 만들어진 SQL과 PostgreSQL에 의해 어떻게 실행되는지 분석 할 필요가 있습니다.