hmm, first of all, if it is not necessary to use C #, the sql management console can perform such a task.
To achieve the best performance, I would call consumer-producer flow concept 2,
- One thread will be the reader responsible for reading items from the database - in this case, I highly recommend using IReader to read values ββand putting them in the cuncurrent queue.
- Another will be a writer who will simply use fileStream to write data from the queue.
You can also achieve much greater productivity by reading the information through the page image, that is, if you know that you will have 100,000 records, divide them into pieces of 1000, ask the reader to read these pieces from the database and put them in the queue.
Although the later solution is more complicated, it will allow you to use your processor in the best way and avoid latency.
source share