1

I have the following code, which "sometimes" gives a timeout error

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

The error message is:

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

How do I extend the timeout period?

oshirowanen
  • 15,297
  • 82
  • 198
  • 350
  • Related: http://stackoverflow.com/questions/8602395/timeout-expired-the-timeout-period-elapsed-prior-to-completion-of-the-operation – Soner Gönül Apr 07 '15 at 12:01

1 Answers1

3

You have to set the command timeout.

From your example you just have to do:

dataAdapter.SelectCommand.CommandTimeout = 60;
Avitus
  • 15,640
  • 6
  • 43
  • 53