延长查询超时时间

Extending query time out period

我有以下代码,"sometimes" 给出超时错误

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];

错误信息是:

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

如何延长超时时间?

您必须设置命令超时。

根据您的示例,您只需要做:

dataAdapter.SelectCommand.CommandTimeout = 60;