Strange File Creation Error

Hi,

I read a CSV file and use a string builder to compile a large string. I have used this for speed.

Once it has built the entire string of 60,000 rows, I write this to a file, I call, BULKLINES.sql

OK, I then have an sql stored procedure which is BULK INSERT, and points to that file. HERE is the wierd part.

When I execute the stored procedure on the file I created it errors, BUT if I open the file with notepad, CTRL-A select all and copy to a new file, lets say BULKLINES_COPY.sql and then run the stored procedure pointing at this copied file, it works great.

I cannot pinpoint the error as the two files are the same with regards to their contents. But yet it will onky work on the copy file.

Could I be writing the file wrong?  I simply use a streamWriter and I have tried the WriteLine and Write Methods

Thanks in advance

Andrew
LVL 20
REA_ANDREWAsked:
Who is Participating?
 
mzalewskiConnect With a Mentor Commented:
Try using ASCII Encoding instead:

new StreamWriter(fileName, true, System.Text.Encoding.ASCII);
0
 
REA_ANDREWAuthor Commented:
Thye error I receive is this

Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 1 (ID).
0
All Courses

From novice to tech pro — start learning today.