简体   繁体   English

插入.txt文件时SQL Server批量插入错误

[英]SQL Server bulk insert error while inserting .txt file

I'm using SQL Server 2012 and when using bulk insert, the following error occurs: 我正在使用SQL Server 2012,并且在使用批量插入时发生以下错误:

Msg 4832, Level 16, State 1, Line 1 Msg 4832,第16级,状态1,第1行
Bulk load: An unexpected end of file was encountered in the data file. 批量加载:在数据文件中遇到了意外的文件结尾。
Msg 7399, Level 16, State 1, Line 1 消息7399,级别16,状态1,第1行
The OLE DB provider "BULK" for linked server "(null)" reported an error. 链接服务器“(null)”的OLE DB提供程序“ BULK”报告了一个错误。 The provider did not give any information about the error. 提供程序未提供有关该错误的任何信息。
Msg 7330, Level 16, State 2, Line 1 Msg 7330,第16级,州2,第1行
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)". 无法从OLE DB提供程序“ BULK”中获取链接服务器“(空)”的行。

My query is: 我的查询是:

BULK INSERT _bulk 
FROM 'D:\Twilight\Personal\Alexander\result.txt'
WITH (FIELDTERMINATOR = ',', ROWTERMINATOR = '\n')

The data contained in my .txt file is: 我的.txt文件中包含的数据是:

1,alex,trichy
2,arun,namakkal
3,shiva,chennai

Most likely your rows are terminated by \\r\\n instead of \\n . 您的行很可能以\\r\\n而不是\\n终止。 You can check this in text editors like Notepad++ or Sublime. 您可以在文本编辑器(如Notepad ++或Sublime)中进行检查。

If the command below works, the line-endings were the issue: 如果以下命令有效,则行尾就是问题所在:

BULK INSERT _bulk 
FROM 'D:\Twilight\Personal\Alexander\result.txt'
WITH (FIELDTERMINATOR = ',', ROWTERMINATOR = '\r\n')

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

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