Reputation: 2108
I have a query that takes long to execute and eventually times out.
My task is just to get all the data from the table for particular dates.
However, the database table does not have indexes on the date column and query takes long time to execute and times out.
This is piece of code I have:
DateTime dateTo = Convert.ToDateTime(data.DateTo);
DateTime dateFrom = Convert.ToDateTime(data.DateFrom);
command.CommandText = "select * from errorlog where errortime between @dateFrom and @dateTo";
command.Parameters.AddWithValue("@dateTo", dateTo);
command.Parameters.AddWithValue("@dateFrom", dateFrom);
da.SelectCommand = command;
da.Fill(ds);
Is there any way to rewrite the logic to improve the performance?
Upvotes: 1
Views: 81
Reputation: 156918
Talk to your DBA. Let him create the index. All other things you are going to 'fix' because of this is just a waste of your time and the time of your users.
Upvotes: 3
Reputation: 14359
Since the query timeout happens because of slow database, few solutions are:
Upvotes: 0