简体   繁体   中英

SQL Server BULK INSERT: Bulk load data conversion error (type mismatch or invalid character for the specified codepage)

Here is my table definition:

CREATE TABLE BillTexts 
(
    SessionNum INT,
    Name VARCHAR(200),
    Part INT,
    BillText VARCHAR(MAX)
)

Here is the code I am using to bulk insert it. I have used the funky delimiters to make sure there are no conflicts (commas, newlines) with what's inside the billtext column.

BULK INSERT BillTexts
FROM texts.csv
WITH (
    DATAFILETYPE = 'char',
    FIELDTERMINATOR = '¬',
    ROWTERMINATOR = '[]{}\r\n'
)

Here is the first couple of lines of my text file.

112¬hconres1¬1¬"A whole bunch of text"[]{} 
112¬hconres1¬2¬"Another whole bunch of text"[]{}

On every line (including lines 1 through 10) I get the error

Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 1 (SessionNum)

Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 2, column 1 (SessionNum)

I honestly have no idea why it's failing to insert. As far as I know this is the only way I can get this data into the table (there is a lot of it).

I don't have an answer, but I have a line of attack: break it down into smaller problems.

Start with a set of data that only contains, say, 5 rows of data. If that still fails, break it down to 5 rows with 1 column--this will test your row delimiters. Then, add the second column back in, to test the column delimiters. Next, add all but the "blob" column, test, and then add the blob back in. Possibly, load just the blob as a single column dataset, see how that works.

Note that you'll need to create specific testing tables for all of the above.

Looking at the problem from multiple perspectives should help narrow down what's going on--what works, what doesn't. (The files are single-byte, not double-byte, right?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM