Determine ROW that caused “unexpected end of file” error in BULK INSERT?

后端 未结 11 1964
闹比i
闹比i 2020-12-16 10:18

i am doing a bulk insert:

DECLARE @row_terminator CHAR;
SET @row_terminator = CHAR(10); -- or char(10)

DECLARE @stmt NVARCHAR(2000);
SET @stmt = \'
  BULK I         


        
11条回答
  •  抹茶落季
    2020-12-16 10:25

    I have a csv file that i import using Bulk

    BULK INSERT [Dashboard].[dbo].[3G_Volume]
    FROM 'C:\3G_Volume.csv'
    WITH
    (
    FIRSTROW = 2,
    FIELDTERMINATOR = '","',
    ROWTERMINATOR = '\n'
    )
    GO
    

    Usually I used this script and it has no problems but in rare occassions.

    I encounter this error..

    "The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error."

    Usually, this happens when the last row have blank values(null).

    You need to link your csv file in MS access db to check the data.. (If your csv is not more than 1.4million rows you can open it in excel)

    Since my data is around 3million rows I need to use access db.

    Then check the number of the last row with blanks and subtract the number of null rows to your total rows for csv.

    if you have 2 blank rows at the end and the total number of rows is 30000005 The script will become like this..

    BULK
    INSERT [Dashboard].[dbo].[3G_Volume]
     FROM 'C:\3G_Volume.csv'
    WITH
    (
    FIRSTROW = 2,
    FIELDTERMINATOR = '","',
    ROWTERMINATOR = '\n',
    Lastrow = 30000003
    )
    GO
    

    Cheers... Mhelboy

提交回复
热议问题