0
votes

I have this little sql script to import a semicolon separated file into a specific table of my database:

BULK
INSERT foo_bar
FROM 'C:\Users\JohnDoe\projects\foo\ftp-data-importator\bar.txt'
WITH
(
FIELDTERMINATOR = ';',
ROWTERMINATOR = '\n',
FIRSTROW = 2,
MAXERRORS = 100000,
ERRORFILE = 'c:\temp\foobar_bulk_log.txt'
)
GO

And it's working like a charm. The only problem is that some special unicode characters like ó or é are not being inserted respecting the encoding of the file.

So I added the next line between the WITH keyword parentheses:

DATAFILETYPE = 'widenative'

And instead of respecting the encoding is breaking the whole execution and giving me the next error:

Msg 4866, Level 16, State 5, Line 5 The bulk load failed. The column is too long in the data file for row 1, column 1. Verify that the field terminator and row terminator are specified correctly. Msg 7301, Level 16, State 2, Line 5 Cannot obtain the required interface ("IID_IColumnsInfo") from OLE DB provider "BULK" for linked server "(null)".

Where is the problem?

2
I would never think SQL server bulk insert is working like a charm, but sometimes it does. Is your file really a Unicode file with a byte order mark? Even in that case I had problems with SQL server. If your file is an ANSI text then instead of DataFileType, try using CodePage=1250. BTW, with Unicode you would use widechar. - Cetin Basoz
Thanks! I solved it replacing the line DATAFILETYPE = 'widenative' with CodePage=1252. Post the comment as answer if you want. You were aiming in the right direction. - VictorArcas

2 Answers

1
votes

Instead of DataFileType try using CODEPAGE=1252.

1
votes

Try specifying widechar instead of widenative Your original statement is using character mode, not native BCP format. Also, ensure the source file is Unicode (not UTF-8).