The first and very important change I made was that I changed my object DateTimeto shortDate(e.g. startDate.ToShortDateString ()), so it removed some of the time from my date, and it really helped with my SQL stored procedure with a parameter DateTime.
2nd change --- read directly from SqlDataReaderand write directly to a text file using the method Read, because it DataTablewill not be held in a long file (for example, 420,000 KB)
using (SqlDataReader rdr = comm.ExecuteReader())
{
while (rdr.Read())
{
file.WriteLine(rdr.GetString(0), true);
}
}
Third change - I increased the wait time
comm.CommandTimeout = 600; ( e.g for 10min)
source
share