Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increasing the Command Timeout for SQL command

I have a little problem and hoping someone can give me some advice. I am running a SQL command, but it appears it takes this command about 2 mins to return the data as there is a lot of data. But the default connection time is 30 secs, how do I increase this, and apply it to this command?

public static DataTable runtotals(string AssetNumberV, string AssetNumber1V) {     DataTable dtGetruntotals;      try     {         dtGetruntotals = new DataTable("Getruntotals");          //SqlParameter AssetNumber = new SqlParameter("@AssetNumber", SqlDbType.VarChar, 6);         //AssetNumber.Value = AssetNumberV;           SqlParameter AssetNumber = new SqlParameter("@AssetNumber", SqlDbType.VarChar, 10);         AssetNumber.Value = AssetNumberV;          SqlParameter AssetNumber1 = new SqlParameter("@AssetNumber1", SqlDbType.VarChar, 10);         AssetNumber1.Value = AssetNumber1V;          SqlCommand scGetruntotals = new SqlCommand("EXEC spRunTotals @AssetNumber,@AssetNumber1 ", DataAccess.AssetConnection);          // scGetruntotals.Parameters.Add(AssetNumber);         scGetruntotals.Parameters.Add(AssetNumber);         scGetruntotals.Parameters.Add(AssetNumber1);          SqlDataAdapter sdaGetruntotals = new SqlDataAdapter();         sdaGetruntotals.SelectCommand = scGetruntotals;         sdaGetruntotals.Fill(dtGetruntotals);          return dtGetruntotals;     }     catch (Exception ex)     {         MessageBox.Show("Error Retriving totals Details: Processed with this error:" + ex.Message);         return null;     } } 
like image 214
CHRISTOPHER MCCONVILLE Avatar asked Aug 26 '13 08:08

CHRISTOPHER MCCONVILLE


People also ask

How do I change the command timeout in SQL?

Select Query Execution from tree on left side and enter command timeout in "Execute Timeout" control. Changing Command Timeout in Server: In the object browser tree right click on the server which give you timeout and select "Properties" from context menu. you can set the value in up/down control.

What is SQL command timeout?

Gets or sets the wait time (in seconds) before terminating the attempt to execute a command and generating an error.


2 Answers

it takes this command about 2 mins to return the data as there is a lot of data

Probably, Bad Design. Consider using paging here.

default connection time is 30 secs, how do I increase this

As you are facing a timeout on your command, therefore you need to increase the timeout of your sql command. You can specify it in your command like this

// Setting command timeout to 2 minutes scGetruntotals.CommandTimeout = 120; 
like image 172
Ehsan Avatar answered Sep 23 '22 10:09

Ehsan


Add timeout of your SqlCommand. Please note time is in second.

// Setting command timeout to 1 second scGetruntotals.CommandTimeout = 1; 
like image 45
Ajay Avatar answered Sep 21 '22 10:09

Ajay