Increasing the Command Timeout for SQL command Increasing the Command Timeout for SQL command sql sql

Increasing the Command Timeout for SQL command


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 minutesscGetruntotals.CommandTimeout = 120;


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

// Setting command timeout to 1 secondscGetruntotals.CommandTimeout = 1;


Since it takes 2 mins to respond, you can increase the timeout to 3 mins by adding the below code

scGetruntotals.CommandTimeout = 180;

Note : the parameter value is in seconds.