Just take the line out:
file = file2;
You cannot change the iteration variable in any way while inside a foreach loop - it is under the compilers control what value it has at all times, not yours!
But...frankly that is some weird code you have going there.
Why on earth are you doing this by calling SQL for each and every character outside the small ASCII set? Do you have any idea how inefficient that is?
If you must do it via SQL (And personally, I wouldn't) then do the whole line as one object in SQL, don't play about with a character here, a character there.
But frankly, I'd do it in C# (not SQL at all), where it's probably one line of code for the whole string if you use Linq...