SQL 명령에 대한 명령 시간 초과 늘리기
나는 약간의 문제가 있고 누군가가 나에게 조언을 줄 수 있기를 바랍니다. SQL 명령을 실행하고 있지만 데이터가 많기 때문에 데이터를 반환하는 데 약 2 분 정도 걸립니다. 하지만 기본 연결 시간은 30 초입니다.이 값을 어떻게 늘려서이 명령에 적용합니까?
public static DataTable runtotals(string AssetNumberV, string AssetNumber1V)
{
DataTable dtGetruntotals;
try
{
dtGetruntotals = new DataTable("Getruntotals");
//SqlParameter AssetNumber = new SqlParameter("@AssetNumber", SqlDbType.VarChar, 6);
//AssetNumber.Value = AssetNumberV;
SqlParameter AssetNumber = new SqlParameter("@AssetNumber", SqlDbType.VarChar, 10);
AssetNumber.Value = AssetNumberV;
SqlParameter AssetNumber1 = new SqlParameter("@AssetNumber1", SqlDbType.VarChar, 10);
AssetNumber1.Value = AssetNumber1V;
SqlCommand scGetruntotals = new SqlCommand("EXEC spRunTotals @AssetNumber,@AssetNumber1 ", DataAccess.AssetConnection);
// scGetruntotals.Parameters.Add(AssetNumber);
scGetruntotals.Parameters.Add(AssetNumber);
scGetruntotals.Parameters.Add(AssetNumber1);
SqlDataAdapter sdaGetruntotals = new SqlDataAdapter();
sdaGetruntotals.SelectCommand = scGetruntotals;
sdaGetruntotals.Fill(dtGetruntotals);
return dtGetruntotals;
}
catch (Exception ex)
{
MessageBox.Show("Error Retriving totals Details: Processed with this error:" + ex.Message);
return null;
}
}
데이터가 많기 때문에 데이터를 반환하는 데 약 2 분이 걸립니다.
나쁜 디자인. 여기에서 페이징을 사용해보십시오.
기본 연결 시간은 30 초입니다. 어떻게 늘릴 수 있습니까?
명령에서 시간 초과에 직면하고 있으므로 sql 명령 의 시간 초과를 늘려야합니다 . 다음과 같이 명령에 지정할 수 있습니다.
// Setting command timeout to 2 minutes
scGetruntotals.CommandTimeout = 120;
당신의 시간 제한을 추가합니다 SqlCommand
. 시간은 초 단위입니다.
// Setting command timeout to 1 second
scGetruntotals.CommandTimeout = 1;
응답하는 데 2 분이 걸리므로 아래 코드를 추가하여 타임 아웃을 3 분으로 늘릴 수 있습니다.
scGetruntotals.CommandTimeout = 180;
참고 : 매개 변수 값은 초 단위입니다.
CommandTimeout을 120으로 설정하는 것은 권장되지 않습니다. 위에서 언급 한대로 페이지 매김을 사용해보십시오. CommandTimeout을 30으로 설정하는 것은 정상으로 간주됩니다. 그 이상은 잘못된 접근 방식으로 간주되며 일반적으로 구현에 문제가 있다고 결론을 내립니다. 이제 세계는 MiliSeconds Approach에서 실행되고 있습니다.
명령 제한 시간을 2 분으로 설정합니다.
scGetruntotals.CommandTimeout = 120;
하지만 저장 프로 시저를 최적화하여 그 시간을 줄일 수 있습니다! 처럼
- 코스를 제거하거나 동안 등
- 페이징 사용
- #tempTable 및 @variableTable 사용
- 조인 된 테이블 최적화
참고 URL : https://stackoverflow.com/questions/18440130/increasing-the-command-timeout-for-sql-command
'UFO ET IT' 카테고리의 다른 글
jQuery.attr () 함수를 사용하여 여러 데이터 속성을 설정할 수 있습니까? (0) | 2020.12.03 |
---|---|
관리자를 사용할 수 없습니다. (0) | 2020.12.03 |
AngularJs 양식의 첫 번째 잘못된 입력에 초점 설정 (0) | 2020.12.03 |
iOS Swift를 사용한 NSURLConnection (0) | 2020.12.03 |
R의 magritrr에서 %> %와 같은 파이썬의 기능성 파이프 (0) | 2020.12.03 |