How to increase timeout of DataAdapter to 3 min? How to increase timeout of DataAdapter to 3 min? sql-server sql-server

How to increase timeout of DataAdapter to 3 min?


You can set the CommandTimeout of the SelectCommand:

adapter.SelectCommand.CommandTimeout = 180; // default is 30 seconds

If you can't establish a connection to the database and you also want to increase that timeout, you have to do that in the connection-string, for example(default is 15 seconds):

"Data Source=(local);Connection Timeout=30;Initial Catalog=AdventureWorks; Integrated Security=SSPI;"

Note that you should use the using-statement for your connection and other objects implementing IDisposable like the OleDbDataAdapter. On that way you ensure that all unmanaged resources are disposed properly:

internal static DataSet executeQuery(string queryString){    DataSet dataSet = new DataSet();    string connectionString = Connection.connectionStringSQL01NavProvider();    using (var connection = new OleDbConnection(connectionString))    using(var adapter = new OleDbDataAdapter(queryString, connectionString))    {        try        {            adapter.Fill(dataSet); // you dont need to open/close the connection with Fill        } catch (Exception ex)        {            Console.WriteLine(ex.Message);            System.Windows.Forms.MessageBox.Show("Error executeQuery().! " + ex.Message);        }    }    return dataSet;}