简体   繁体   English

SQL Server批量插入转换错误MSG 4864 HRESULT 0x80004005

[英]SQL Server Bulk Insert conversion error MSG 4864 HRESULT 0x80004005

This is my first question here (I have been lurking and learning a lot in the past few years). 这是我的第一个问题(过去几年来我一直在潜伏和学习很多东西)。

I have a problem with Bulk Insert in SQL Server 2012, it returns errors. 我在SQL Server 2012中批量插入有问题,它返回错误。

Bulk Insert code: 批量插入代码:

--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
);

Errors returned: 返回错误:

Msg 4864, Level 16, State 1, Line 2 消息4864,第16级,州1,第2行
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 2, column 1 (TStamp). 第2行第1列(TStamp)的批量加载数据转换错误(类型不匹配或指定代码页的字符无效)。

Here is the data specified in the message: 这是消息中指定的数据:

    2|yyyy-mm-dd hh:mm:ss|||GTM|||cccccccc||||||

My format file (so that we can keep Swedish letters in the data) 我的格式文件(以便我们可以在数据中保留瑞典字母)

    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 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

Thanks in advance! 提前致谢! If you have any comments on the question itself or if you need any details please don't hesitate to ask. 如果您对问题本身有任何意见或需要任何详细信息,请随时询问。

Allowed formats for DATETIME : DATETIME允许的格式:

  • YYYY-MM-DDThh:mm:ss[.mmm]
  • YYYYMMDD[ hh:mm:ss[.mmm]]

The things between rectangular brackets are optional. 方括号之间的内容是可选的。 The T in the first format is the character T . T第一格式是字符T In the second version there's a space between DD and hh (if hh is present) 在第二个版本中, DDhh之间有一个空格(如果存在hh

Also, your separators are missing from your format file. 此外,格式文件中缺少分隔符。 You need to provide valid field terminators in your format file if you specify it in the BULK INSERT statement. 如果在BULK INSERT语句中指定了格式文件,则需要提供有效的字段终止符。 So you will need to specify | 因此,您需要指定| as field terminator in your format file. 作为格式文件中的字段终止符。 If your row terminator is \\r\\n then you need to specify that as your final field terminator in the format file. 如果行终止符为\\r\\n则需要在格式文件中将其指定为最终字段终止符。

See the official documentation on Create a Format File (SQL Server) on how to do that. 请参阅有关Create a Format File (SQL Server)的官方文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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