B
Bossie
Hi All,
I am having a little trouble with a StreamReader. I am currently reading a
pipe delimited file with around 1.8 million records (total size 150MB) and,
based on a flag, insert update or delete a record in a SQL Server DB using
System.Data.SqlClient.
So I do a ReadLine() on the streamreader, do my action and then step to the
next line. (Note I am using SqlBulkCopy to do the DB side, but I don't think
that really affects by problem).
Every once in a while (say every second or third complete run), the
ReadLine() pointer gets confused and jumps back somewhere between 30-60 lines
in memory and reprocess the records it has jumped back over. It does this
until it gets to where it was before the backwards jump and then jump
forwards to where it was meant to be originally. So for a simple example,
lets say I have records as follows:
1|Jack
2|John
3|Steve
4|Mary
5|Sarah
6|Michelle
7|Brian
8|Sally
9|David
The process starts and processes 1, then 2, then 3, then 4, then 5 then
jumps back (2 spaces for simplicity) to 3 again (instead of 6) and
reprocessed it, then it advances to 4 and reprocesses it (instead of 7). When
it gets back to 5 it realizes that it should have been at 8 now, so it jumps
to 8 and continues merily.
So essencially, 3 and 4 was processed twice and 6 and 7 was skipped. The
problem is that this is intermittend, it doesn't happen all the time and it
doesn't happen at the same place.
A little additional information that may be relevant:
- I'm running the process from within a thread
- The process is running on a VM with 2GB of memory
- Error happens both from running it as debug inside VS2008 and as a
standalone exe in release build
I can only assume it is either a memory leak or an issue with threading, but
any advice will help.
I am having a little trouble with a StreamReader. I am currently reading a
pipe delimited file with around 1.8 million records (total size 150MB) and,
based on a flag, insert update or delete a record in a SQL Server DB using
System.Data.SqlClient.
So I do a ReadLine() on the streamreader, do my action and then step to the
next line. (Note I am using SqlBulkCopy to do the DB side, but I don't think
that really affects by problem).
Every once in a while (say every second or third complete run), the
ReadLine() pointer gets confused and jumps back somewhere between 30-60 lines
in memory and reprocess the records it has jumped back over. It does this
until it gets to where it was before the backwards jump and then jump
forwards to where it was meant to be originally. So for a simple example,
lets say I have records as follows:
1|Jack
2|John
3|Steve
4|Mary
5|Sarah
6|Michelle
7|Brian
8|Sally
9|David
The process starts and processes 1, then 2, then 3, then 4, then 5 then
jumps back (2 spaces for simplicity) to 3 again (instead of 6) and
reprocessed it, then it advances to 4 and reprocesses it (instead of 7). When
it gets back to 5 it realizes that it should have been at 8 now, so it jumps
to 8 and continues merily.
So essencially, 3 and 4 was processed twice and 6 and 7 was skipped. The
problem is that this is intermittend, it doesn't happen all the time and it
doesn't happen at the same place.
A little additional information that may be relevant:
- I'm running the process from within a thread
- The process is running on a VM with 2GB of memory
- Error happens both from running it as debug inside VS2008 and as a
standalone exe in release build
I can only assume it is either a memory leak or an issue with threading, but
any advice will help.