2015-04-07 28 views
1

我有以下代码,其中“有时”给出了超时错误扩展查询超时时段

string select = @"query goes here"; 
connection1 = new SqlConnection("connection string goes ehre"); 
SqlDataAdapter dataAdapter = new SqlDataAdapter(select, connection1); 
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter); 
DataSet ds = new DataSet(); 
dataAdapter.Fill(ds); 
dataGridView1.DataSource = ds.Tables[0]; 

的错误信息是:

超时过期。在完成 操作或服务器没有响应之前已经超时。

如何延长超时时间?

+0

相关:http://stackoverflow.com/questions/8602395/timeout-expired-the-timeout-period-elapsed-prior-to-completion -of-的操作 –

回答

3

您必须设置命令超时。

从你的例子中,你只需要做:

dataAdapter.SelectCommand.CommandTimeout = 60;