Import text file to SQL Server using Bulk Insert

riza picture riza · Jan 23, 2013 · Viewed 41.6k times · Source

This is my sql

BULK INSERT dbo.Account FROM 'G:\Import\Account3.txt'
WITH
(
    FIELDTERMINATOR = '" | "'
)
GO

When I run the sql i got this error

Msg 4866, Level 16, State 1, Line 1
The bulk load failed.

The column is too long in the data file for row 1, column 1. Verify that the field terminator and row terminator are specified correctly.

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

Please help me. I already tried many ways but still get the same error.

Answer

Tom Lint picture Tom Lint · Apr 17, 2015

From your example SQL, it seems you are missing a ROWTERMINATOR statement, specifying how rows are to be differentiated from one another.

Your query would then become something like

BULK INSERT dbo.Account FROM 'G:\Import\Account3.txt'
WITH
(
FIELDTERMINATOR = '" | "',
ROWTERMINATOR = '\r\n'
)
GO