시간 제한을 설정하기 전에 tableAdapter에서 GetData() 메서드를 호출해야합니다. 그렇지 않으면 SelectCommand가 초기화되지 않습니다.
protected void setAdapterTimeout(SqlDataAdapter da, int timeOut = 120)
{
if (da.SelectCommand != null)
da.SelectCommand.CommandTimeout = timeOut;
}
다음과 같이 호출 :
//Replacing AccessoryTableAdapter with your table Adapter
AccessoryTableAdapter ata = new AccessoryTableAdapter();
setAdapterTimeout(ata.Adapter);
편집 : 확장 메서드가 멋진!
public static class Extensions
{
public static void setAdapterTimeout(this SqlDataAdapter da, int timeOut = 120)
{
if (da.SelectCommand != null)
da.SelectCommand.CommandTimeout = timeOut;
if (da.InsertCommand != null)
da.InsertCommand.CommandTimeout = timeOut;
}
}
다음 전화 : 내 경우
AccessoryTableAdapter ata = new AccessoryTableAdapter();
ata.Adapter.setAdapterTimeout(120);