SQL 服务器大容量插入转换错误 MSG 4864 HRESULT 0x80004005
SQL Server Bulk Insert conversion error MSG 4864 HRESULT 0x80004005
这是我的第一个问题(这几年我一直在潜伏学习)
我在 SQL Server 2012 中遇到批量插入问题,它 returns 错误。
批量插入代码:
--DROP TABLE dbname.logg20160203
BULK INSERT dbname.logg20160204
FROM 'x:\xxxx\SYSTEMID\log20151005t.ms'
WITH
(
FIRSTROW = 1,
ORDER (Id),
CODEPAGE = 'RAW',
--DATAFILETYPE = 'char',
FIELDTERMINATOR = '|',
--ROWTERMINATOR = '\n',
--ROWTERMINATOR = '\r',
--ROWTERMINATOR = '\n\r',
--ROWTERMINATOR = '\r\n',
ROWTERMINATOR = '0x0a',
TABLOCK, --Performance
ERRORFILE = 'x:\xxxx\SYSTEMID\err104.log',
FORMATFILE = 'x:\xxxx\SYSTEMID\formatfile-n.fmt',
KEEPNULLS
);
返回错误:
Msg 4864, Level 16, State 1, Line 2
Bulk load data conversion error (type mismatch or invalid character
for the specified codepage) for row 2, column 1 (TStamp).
消息中指定的数据如下:
2|yyyy-mm-dd hh:mm:ss|||GTM|||cccccccc||||||
我的格式文件(这样我们就可以在数据中保留瑞典字母)
11.0
14
1 SQLCHAR 0 0 "" 1 col1 ""
2 SQLCHAR 0 19 "\r\n" 2 col2 ""
3 SQLCHAR 0 20 "" 3 col3 Finnish_Swedish_CI_AS
4 SQLCHAR 0 5 "" 4 col4 Finnish_Swedish_CI_AS
5 SQLCHAR 0 10 "" 5 col5 Finnish_Swedish_CI_AS
6 SQLCHAR 0 20 "" 6 col6 Finnish_Swedish_CI_AS
7 SQLCHAR 0 20 "" 7 col7 Finnish_Swedish_CI_AS
8 SQLCHAR 0 100 "" 8 col8 Finnish_Swedish_CI_AS
9 SQLCHAR 0 10 "" 9 col9 Finnish_Swedish_CI_AS
10 SQLCHAR 0 20 "" 10 col10 Finnish_Swedish_CI_AS
11 SQLCHAR 0 20 "" 11 col11 Finnish_Swedish_CI_AS
12 SQLCHAR 0 20 "" 12 col12 Finnish_Swedish_CI_AS
13 SQLCHAR 0 20 "" 13 col13 Finnish_Swedish_CI_AS
14 SQLCHAR 0 20 "" 14 col14 Finnish_Swedish_CI_AS
err104.log
Row 2 File Offset 331 ErrorFile Offset 0 - HRESULT 0x80004005
Row 3 File Offset 637 ErrorFile Offset 306 - HRESULT 0x80004005
Row 4 File Offset 978 ErrorFile Offset 647 - HRESULT 0x80004005
Row 5 File Offset 1278 ErrorFile Offset 947 - HRESULT 0x80004005
Row 6 File Offset 1627 ErrorFile Offset 1296 - HRESULT 0x80004005
Row 7 File Offset 1946 ErrorFile Offset 1615 - HRESULT 0x80004005
Row 8 File Offset 2300 ErrorFile Offset 1969 - HRESULT 0x80004005
Row 9 File Offset 2597 ErrorFile Offset 2266 - HRESULT 0x80004005
Row 10 File Offset 2940 ErrorFile Offset 2609 - HRESULT 0x80004005
Row 11 File Offset 3261 ErrorFile Offset 2930 - HRESULT 0x80004005
Row 12 File Offset 3564 ErrorFile Offset 3233 - HRESULT 0x80004005
提前致谢!如果您对问题本身有任何意见或需要任何详细信息,请随时提出。
DATETIME 允许的格式:
YYYY-MM-DDThh:mm:ss[.mmm]
YYYYMMDD[ hh:mm:ss[.mmm]]
方括号内的内容为可选项。第一种格式中的T
是字符T
。在第二个版本中,DD
和 hh
之间有一个 space(如果存在 hh
)
此外,您的格式文件中缺少分隔符。如果在 BULK INSERT
语句中指定,则需要在格式文件中提供有效的字段终止符。因此,您需要在格式文件中指定 |
作为字段终止符。如果您的行终止符是 \r\n
,那么您需要在格式文件中将其指定为最终字段终止符。
请参阅有关 Create a Format File (SQL Server)
的官方文档,了解如何执行此操作。
这是我的第一个问题(这几年我一直在潜伏学习)
我在 SQL Server 2012 中遇到批量插入问题,它 returns 错误。
批量插入代码:
--DROP TABLE dbname.logg20160203
BULK INSERT dbname.logg20160204
FROM 'x:\xxxx\SYSTEMID\log20151005t.ms'
WITH
(
FIRSTROW = 1,
ORDER (Id),
CODEPAGE = 'RAW',
--DATAFILETYPE = 'char',
FIELDTERMINATOR = '|',
--ROWTERMINATOR = '\n',
--ROWTERMINATOR = '\r',
--ROWTERMINATOR = '\n\r',
--ROWTERMINATOR = '\r\n',
ROWTERMINATOR = '0x0a',
TABLOCK, --Performance
ERRORFILE = 'x:\xxxx\SYSTEMID\err104.log',
FORMATFILE = 'x:\xxxx\SYSTEMID\formatfile-n.fmt',
KEEPNULLS
);
返回错误:
Msg 4864, Level 16, State 1, Line 2
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 2, column 1 (TStamp).
消息中指定的数据如下:
2|yyyy-mm-dd hh:mm:ss|||GTM|||cccccccc||||||
我的格式文件(这样我们就可以在数据中保留瑞典字母)
11.0
14
1 SQLCHAR 0 0 "" 1 col1 ""
2 SQLCHAR 0 19 "\r\n" 2 col2 ""
3 SQLCHAR 0 20 "" 3 col3 Finnish_Swedish_CI_AS
4 SQLCHAR 0 5 "" 4 col4 Finnish_Swedish_CI_AS
5 SQLCHAR 0 10 "" 5 col5 Finnish_Swedish_CI_AS
6 SQLCHAR 0 20 "" 6 col6 Finnish_Swedish_CI_AS
7 SQLCHAR 0 20 "" 7 col7 Finnish_Swedish_CI_AS
8 SQLCHAR 0 100 "" 8 col8 Finnish_Swedish_CI_AS
9 SQLCHAR 0 10 "" 9 col9 Finnish_Swedish_CI_AS
10 SQLCHAR 0 20 "" 10 col10 Finnish_Swedish_CI_AS
11 SQLCHAR 0 20 "" 11 col11 Finnish_Swedish_CI_AS
12 SQLCHAR 0 20 "" 12 col12 Finnish_Swedish_CI_AS
13 SQLCHAR 0 20 "" 13 col13 Finnish_Swedish_CI_AS
14 SQLCHAR 0 20 "" 14 col14 Finnish_Swedish_CI_AS
err104.log
Row 2 File Offset 331 ErrorFile Offset 0 - HRESULT 0x80004005
Row 3 File Offset 637 ErrorFile Offset 306 - HRESULT 0x80004005
Row 4 File Offset 978 ErrorFile Offset 647 - HRESULT 0x80004005
Row 5 File Offset 1278 ErrorFile Offset 947 - HRESULT 0x80004005
Row 6 File Offset 1627 ErrorFile Offset 1296 - HRESULT 0x80004005
Row 7 File Offset 1946 ErrorFile Offset 1615 - HRESULT 0x80004005
Row 8 File Offset 2300 ErrorFile Offset 1969 - HRESULT 0x80004005
Row 9 File Offset 2597 ErrorFile Offset 2266 - HRESULT 0x80004005
Row 10 File Offset 2940 ErrorFile Offset 2609 - HRESULT 0x80004005
Row 11 File Offset 3261 ErrorFile Offset 2930 - HRESULT 0x80004005
Row 12 File Offset 3564 ErrorFile Offset 3233 - HRESULT 0x80004005
提前致谢!如果您对问题本身有任何意见或需要任何详细信息,请随时提出。
DATETIME 允许的格式:
YYYY-MM-DDThh:mm:ss[.mmm]
YYYYMMDD[ hh:mm:ss[.mmm]]
方括号内的内容为可选项。第一种格式中的T
是字符T
。在第二个版本中,DD
和 hh
之间有一个 space(如果存在 hh
)
此外,您的格式文件中缺少分隔符。如果在 BULK INSERT
语句中指定,则需要在格式文件中提供有效的字段终止符。因此,您需要在格式文件中指定 |
作为字段终止符。如果您的行终止符是 \r\n
,那么您需要在格式文件中将其指定为最终字段终止符。
请参阅有关 Create a Format File (SQL Server)
的官方文档,了解如何执行此操作。