【发布时间】:2011-05-09 04:49:48
【问题描述】:
在使用 C#.NET、Windows Forms 的程序中是否有可能增加查询执行超时时间?
在我的程序中,我正在循环执行一个查询。在前两次迭代中,查询每次在 10 秒内执行。在第三次迭代中,查询完成大约需要 40-50 秒,现在我无法从该查询中提取数据,因为引发了超时异常并且执行流程转到 catch 块,其中对应的显示错误信息。
是否有可能在 Windows 应用程序中使用 C#.NET 执行耗时超过 30 秒的查询?
下面是我的代码:
try
{
tab = "dbo.basic_sp_mst";
error1 = "" + site + "." + orgname + "";
ls = "" + site + "." + site + "." + tab + "";
SqlDataAdapter da2 = new SqlDataAdapter("select * from " + ls + " where (last_updated_date between(getdate()-3) and (getdate()-1)) order by last_updated_date,bsp_item_cd", con);
DataSet ds2 = new DataSet();
da2.Fill(dt5);
dt6 = dt5;
SqlDataAdapter daa = new SqlDataAdapter("select a. bsp_item_cd ,a.bsp_mrp,a.last_updated_date,b.bsp_item_cd ,b.bsp_mrp,b.last_updated_date,c.name from basic_sp_mst a," + ls + " b,sys.servers c where a.bsp_item_cd = b.bsp_item_cd and a.bsp_mrp<> b.bsp_mrp and a.bsp_org_cd=" + s + " and c.name<>'001' and c.name='" + site + "'", con);......................(this is the main query) if this query is taking more than 30sec it is going to catch block.......
DataSet dss = new DataSet();
daa.Fill(dt7);
dt8 = dt7;
}
catch (Exception ex)
{
msg2 = " query time out error at store id:" + error1 + "";
dataGridView8.Rows.Add(msg2);
}
【问题讨论】: