Bulk Insert

  • Hi,

    I am trying to bulk load data from a txt file into a table.

    I keep receiving this error from SQL Server:

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

    The file as the following structure:

    Sessao|CODRF|

    7|4.01|

    It's in the right place and with the right name. Can someone help undestand why this message happens?

    Thanks.

  • Bulk command:

    exec('BULK INSERT sessoes1 FROM ''c:\sgrs\SGRS_SGCTCentral_7_20111111102846.rar_Dir\sessao.txt''

    with (FIRSTROW =2,FIELDTERMINATOR =''|'',

    ROWTERMINATOR =''|'', tablock)')

    Table structure:

    create table Sessoes1(Sessao int, Codrf varchar(5))

  • this errors comes usually if the file is opened While running the bulk insert command.

  • the file is not open.

    It's closed.

  • Re-write the query to match with this example...

    Example:

    DECLARE @bulk_cmd varchar(1000)

    SET @bulk_cmd = 'BULK INSERT AdventureWorks2008R2.Sales.SalesOrderDetail

    FROM ''<drive>:\<path>\<filename>''

    WITH (ROWTERMINATOR = '''+CHAR(10)+''')'

    EXEC(@bulk_cmd) -- Focus here

  • make sure you check for an extra carriage return in your source text file (ie., extra line with no content).

  • I don't think ROWTERMINATOR should be pipe '|'. It should be '\r' or '&#92n' or '\r&#92n'. The latter is default.

    --Vadim R.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply