简体   繁体   English

批量插入不插入数据

[英]Bulk INSERT not inserting data

When running the code below management studio shows an error in which it is set down. 运行以下代码时,Management Studio会显示一个错误,该错误已将其设置为错误。

I need to insert simple text data into the tables through BULK INSERT. 我需要通过BULK INSERT将简单的文本数据插入表中。 The code for insertion is as follows: 插入代码如下:

BULK INSERT Pais FROM 'C:\[bulkdata]\shared\01-Pais.txt' 
WITH(MAXERRORS = 0, CODEPAGE = 'ACP', FIELDTERMINATOR = 'ø', ROWTERMINATOR = '\n', KEEPNULLS,
ERRORFILE = 'C:\[bulkdata]\shared\teste.txt')

The file I'm using to test this command has only one line for inserting data, teste.txt: 我用来测试此命令的文件只有一行用于插入数据, teste.txt:

BrasilØ01058

The error returned is as follows: 返回的错误如下:

Msg 4832, Level 16, State 1, Line 1
Bulk load: An unexpected end of file was encountered in the data file.
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".

teste.txt: teste.txt:

BrasilØ01058BrasilØ01058

It seems to me that this is trying to insert the value twice on the same line, but as the setting shows, it usually inserts into other projects. 在我看来,这是试图在同一行上两次插入值,但是正如设置所示,它通常会插入到其他项目中。 Can my user be without permission? 我的用户可以未经允许吗? I have already created a specific user with all permissions and also set the server the permission to perform bulk operations. 我已经创建了具有所有权限的特定用户,并且还为服务器设置了执行批量操作的权限。

teste.txt.Error.Txt: teste.txt.Error.Txt:

Row 1 File Offset 0 ErrorFile Offset 0 - HRESULT 0x80004005

在此处输入图片说明

It seems to be a character issue, you can try with another one like § . 这似乎是一个character问题,您可以尝试使用另一个类似§character You just need to do a little tweak: 您只需要做一些调整:

FIELDTERMINATOR = '§'

And your 01-Pais.txt file: 和您的01-Pais.txt文件:

Brasil§01058     

Update: It seems that also a mix of database collation and file encoding issue, could have messing up the bulk operation. 更新:似乎数据库排序规则和文件编码问题的混合,也可能使bulk操作混乱。 Saving the file as ANSI , instead of UTF-8 seems to have corrected the original issue. 将文件另存为ANSI而不是UTF-8似乎已解决了原始问题。 It seems that also using CODEPAGE=1252 or DATAFILETYPE = 'widechar' should have fixed the issue. 似乎也可以使用CODEPAGE=1252DATAFILETYPE = 'widechar'来解决此问题。

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

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