添加 DATAFILETYPE='widenative' 时批量插入中断
Bulk insert breaks when adding DATAFILETYPE='widenative'
我有这个小 sql 脚本可以将分号分隔的文件导入我数据库的特定 table:
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
而且效果非常好。
唯一的问题是一些特殊的 unicode 字符,如 ó 或 é 没有按照文件的编码插入。
所以我在 WITH 关键字括号之间添加了下一行:
DATAFILETYPE = 'widenative'
而不是尊重编码破坏了整个执行并给我下一个错误:
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)".
问题出在哪里?
尝试指定 widechar
而不是 widenative
您的原始语句使用的是字符模式,而不是本机 BCP 格式。另外,确保源文件是 Unicode(不是 UTF-8)。
尝试使用 CODEPAGE=1252 而不是 DataFileType。
我有这个小 sql 脚本可以将分号分隔的文件导入我数据库的特定 table:
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
而且效果非常好。 唯一的问题是一些特殊的 unicode 字符,如 ó 或 é 没有按照文件的编码插入。
所以我在 WITH 关键字括号之间添加了下一行:
DATAFILETYPE = 'widenative'
而不是尊重编码破坏了整个执行并给我下一个错误:
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)".
问题出在哪里?
尝试指定 widechar
而不是 widenative
您的原始语句使用的是字符模式,而不是本机 BCP 格式。另外,确保源文件是 Unicode(不是 UTF-8)。
尝试使用 CODEPAGE=1252 而不是 DataFileType。