Sunday, March 25, 2012

BULK INSERT UTF8 File ERROR 4864 on first row first column

we try to import a UTF8 File (at first with SSIS BULK INSERT but now with SQL to track down the errors) and always face the same issue - the first row does not import with error "Msg 4864, Level 16, State 1, Line 10 Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 1 (PSGT_ID)."

The Statements see below. We need to use utf8 because thets the only we can get - with ansi oder unicode it works - so why not utf8? (Codepage 65001?)

--CREATE TABLE [BULKTEST](
-- [PSGT_ID] [numeric](38, 0) NOT NULL primary key,
-- [PSGT_PSG_ID] [numeric](38, 0) NOT NULL,
-- [PSGT_PSP_ID] [numeric](38, 0) NOT NULL,
-- [PSGT_KURZTEXTM] [nvarchar](5) COLLATE Latin1_General_CI_AS NULL,
-- [PSGT_TEXT] [nvarchar](40) COLLATE Latin1_General_CI_AS NULL, -
- [PSGT_AENDDATUM] [datetime] NOT NULL)

truncate table [BULKTEST]
BULK INSERT [BULKTEST] FROM 'C:\test.txt' WITH( CHECK_CONSTRAINTS, CODEPAGE='65001', DATAFILETYPE='char', FIELDTERMINATOR='|', ROWTERMINATOR='\n')
select * from [BULKTEST]

As test data you could use something like this

1|2|3|4|5|2006-01-01
2|2|3|4|5|2006-01-01
3|2|3|4|5|2006-01-01
4|2|3|4|5|2006-01-01

in notepad in a text file stored as UTF8!

We really need help on this!

Best regards, HANNES

Try using the DATAFILETYPE = 'widechar'. You can also try using a format file.|||

I have tried widechar and also a format file - but it stays the same.

Maybe we are a little bit further - could it by that notepad incorrectly adds some characters at the beginning of the file?

Like  - if i display them on the comandline with type <filename>?

LG HANNES

|||Check this Blog http://sqlblogcasts.com/blogs/dong/archive/2006/11/27/how-to-bulk-insert-your-user-defined-types-udt.aspx in this case.

No comments:

Post a Comment