2014-04-28 2 views
0

좋아, 나는 일련의 저장 프로 시저 호출에서 SQL Server 2008의 정보를 얻는 C#으로 작성된 프로그램을 가지고 있습니다. 내 연결 문자열 :Windows Server 2008 R2의 연결 시간 초과 = 0

Data Source={0};Initial Catalog={1}; Integrated Security=True; Connection Timeout=0 

{0}과 {1} 변수에 의해 채워진다.
정보가 너무 커질 수 있고 시간이 좀 걸릴 수 있으므로 제한 시간은 0입니다.
첫 번째 프로 시저가 원활하게 실행되고 그 결과를 반환하지만 두 번째 프로 시저가 프로그램을 중지하고 잠에서 깨어나지 않습니다. 동결하지 않고 쿼리가 infinetly를 실행하기를 기다리고 있습니다. 재미있는 점은 실행하면 프로그램을 내 컴퓨터 (Windows 7)에 모두 잘 작동합니다 (4 초 실행하려면),하지만 서버 (Windows Server 2008 R2)에서이 이상한 동작을 가져옵니다. 나는 15와 같은 다른 번호로이 변경 연결 시간 제한을 해결할 수 있었지만 질문은 왜입니까?
내 코드 :
첫 번째 PROC :

public static bool WorkdayCheck(string sp_name, DateTime CheckDate) 
{ 
    SqlConnection conn = new SqlConnection(ConnectionString); 
    SqlCommand cmd = new SqlCommand(); 
    cmd = new SqlCommand(sp_name, conn); 
    cmd.CommandType = CommandType.StoredProcedure; 
    cmd.CommandTimeout = 0; //unlimited 
    cmd.Parameters.AddWithValue("@checkdate", CheckDate); 
    var work = cmd.Parameters.Add("@work", SqlDbType.Bit); 
    work.Direction = ParameterDirection.Output; 
    conn.Open(); 
    cmd.ExecuteNonQuery(); 
    conn.Close(); 
    if ((bool)cmd.Parameters["@work"].Value) return true; 
    else return false; 
} 

두 번째 PROC : MSDN에서

static DataTable GetSql(string sp_name, params string[] vars) 
{ 
    SqlConnection.ClearAllPools(); //added this hoping it'd help - it didn't 
    DataTable DT = new DataTable(); 
    SqlConnection conn = new SqlConnection(ConnectionString); 
    SqlDataAdapter da = new SqlDataAdapter(); 
    da.SelectCommand = new SqlCommand(sp_name, conn); 
    da.SelectCommand.CommandType = CommandType.StoredProcedure; 
    da.SelectCommand.CommandTimeout = 0; //unlimited 
    da.SelectCommand.Parameters.AddWithValue("@date_b_d", vars[0]); 
    da.SelectCommand.Parameters.AddWithValue("@broker_id_s", vars[1]); 
    da.SelectCommand.Parameters.AddWithValue("@dogovor_id_s", vars[2]); 
    DataSet ds = new DataSet(); 
    da.Fill(ds, "orders_list"); 
    DT = ds.Tables["orders_list"]; 
    return DT; 
} 

답변

0

:

You can set the amount of time a connection waits to time out by using the ConnectTimeout or Connection Timeout keywords in the connection string. 
A value of 0 indicates no limit, and should be avoided in a ConnectionString because an attempt to connect waits indefinitely. 

더 많은 정보 here

+0

나는 그것을 안다. 내 저장 프로 시저가 Windows 7에서 4 초 후 Timeout = 0으로 실행됩니다. – Vadim

관련 문제