System.ComponentModel.Win32Exception: wait operation completed

I need to read very large data, approximately 300,000 rows, from SQL tables and write it to a text file in my application (.net application and using C #). I have a stored procedure to read the data, and I'm using DataAdapter, and DataSetin your code to get the data, but I get an error message

Expected Pending Operation

when he completed dataAdapter.Fill(dataSet). I tried to change the timeout value, but that did not work. I tried different approaches, but nothing works. It works for multiple rows, but it does not work for big data. I cannot capture small data because they need whole data in one text file

+1
source share
2 answers

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)
+1
source

See if you can split one query into several and execute it at the same time and join the results at the end of all selections.

Or even using DataReader will help.

0

Source: https://habr.com/ru/post/1626731/


All Articles