2013-07-05 4 views
2

asp.net MVC 페이지에서 작업 시간을 처리하는 방법에 대한 질문이 있습니다. 데이터베이스 SQL Server를 쿼리하는 페이지를로드하는 동안 제품을로드합니다. 그리고 언젠가는 기다리는 작업 시간을 알려줍니다. 그것을 다루는 방법.기다리는 작업 시간 초과 MVC

+0

검토 코드 .. 확인하여 SQL 쿼리, 그것은 복용과 자원이 .. –

답변

4

매우 긴 쿼리를 실행할 때 대기 작업 시간 초과 예외를 피하려면 SQL 명령 속성을 변경하고 제한 시간을 호출하기 전에 명령이 더 오래 대기하도록하십시오.

using System; 
using System.Data.SqlClient; 
/// 
public class A { 
    /// 
    public static void Main() { 
    string connectionString = ""; 
    // Wait for 5 second delay in the command 
    string queryString = "waitfor delay '00:00:05'"; 
    using (SqlConnection connection = new SqlConnection(connectionString)) { 
     connection.Open(); 
     SqlCommand command = new SqlCommand(queryString, connection); 
     // Setting command timeout to 1 second 
     command.CommandTimeout = 1; 
      try { 
       command.ExecuteNonQuery(); 
       } 
      catch (SqlException e) { 
       Console.WriteLine("Got expected SqlException due to command timeout "); 
       Console.WriteLine(e); 
     } 
    } 
} 

} SQL 쿼리에 Linq에의

실행는 &가의 DataContext 클래스의 CommandTimeout이 속성의 기본 값을 초과 시간이 오래 걸릴 수도 있습니다. 기본값은 30 초입니다. LINQ to SQL DataContext 개체를 만들고 쿼리를 호출 할 때마다 CommandTimeout 값을 설정할 수 있습니다.

#region Constructors 

    /// <summary> 
    /// Initializes a new FrameworkEntities object using the connection string found in the 'FrameworkEntities' section of the application configuration file. 
    /// </summary> 
    public FrameworkEntities() : base("name=FrameworkEntities", "FrameworkEntities") 
    { 
     this.ContextOptions.LazyLoadingEnabled = true; 
     this.CommandTimeout = 300; 
     OnContextCreated(); 
    } 

    /// <summary> 
    /// Initialize a new FrameworkEntities object. 
    /// </summary> 
    public FrameworkEntities(string connectionString) : base(connectionString, "FrameworkEntities") 
    { 
     this.ContextOptions.LazyLoadingEnabled = true; 
     this.CommandTimeout = 300; 
     OnContextCreated(); 
    } 

    /// <summary> 
    /// Initialize a new FrameworkEntities object. 
    /// </summary> 
    public FrameworkEntities(EntityConnection connection) : base(connection, "FrameworkEntities") 
    { 
     this.ContextOptions.LazyLoadingEnabled = true; 
     this.CommandTimeout = 300; 
     OnContextCreated(); 
    } 

    #endregion 
+0

'command.CommandTimeout = 0 얼마나 많은 CPU,'무한 될 것인가? –

+0

0은 무한 타임 아웃입니다. SQL SERVER 인스턴스의 응답이 두 개 이상의 네트워크 패킷으로 나눠지면 연결이 잘못 연결되어 일반 네트워크 오류가 발생합니다. – AnandMohanAwasthi

+0

어디서나 그러한 문서를 찾을 수 없었습니다. 고마워. –