The StreamReader.Close() command calls the Dispose() command, passing a value of true (the Using() construct does the same thing). I have tried calling Dispose() and while it executed successfully it didn't solve the issue.
Yeah, I knew that. But worth a try.
For other readers, I've reposted the code, but with markup tags to make it easier to read.
private void ProcessTextFile(string FileName)
{
var file = new System.IO.StreamReader(FileName);
int row = 0;
string line;
try
{
while ((line = file.ReadLine()) != null)
{
if(!string.IsNullOrEmpty(line))
{
//line processing & insert into db is done here
}
}
//final db insert
}
catch (Exception e)
{
throw e;
}
finally
{
//also tried file.Dispose(); here
file.Close();
}
}
private void ProcessTextFile(string FileName)
{
int row = 0;
string line;
using (var file = new System.IO.StreamReader(importFullFileName))
{
try
{
while ((line = file.ReadLine()) != null)
{
if(!string.IsNullOrEmpty(line))
{
//line processing & insert into db is done here
}
}
//final db insert
}
catch (Exception e)
{
throw e;
}
}
}
Just a quick aside - may I ask why you are using streamreaders rather than standard SSIS dataflows to do file imports?
If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.