简体   繁体   中英

SQL Server bulk insert error while inserting .txt file

I'm using SQL Server 2012 and when using bulk insert, the following error occurs:

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)".

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:

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

Most likely your rows are terminated by \\r\\n instead of \\n . You can check this in text editors like Notepad++ or 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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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