Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bulk Insert csv trouble

I have SQL Server 2014 (v12.0.2000). On that server I execute BULK INSERT for about 200 files in range from 1 kB to 35 MB in this way:

BULK INSERT [MYDB].[dbo].[my_table]
FROM 'C:\Docs\csv\001.csv'
WITH 
    (FIRSTROW = 1,
     FIELDTERMINATOR = ',',
     ROWTERMINATOR = '\n',
     DATAFILETYPE = 'char',
     TABLOCK,
     KEEPNULLS);

All my .csv files are syntactically correct. In that way everything works for 2 days.

After that I suddenly get this error:

Msg 0, Level 11, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.

And even files that have been inserted previously now are discarded. When I try to insert manually file with one row, it also raises error.

P.S. There is enough disk space on my hard drive.

like image 481
AlGiorgio Avatar asked Feb 10 '26 17:02

AlGiorgio


2 Answers

Possible cause

  1. According to this Microsoft artilce :FIX: An error message may occur when you run a "BULK INSERT" query on a database that uses the "BULK_LOGGED" or "SIMPLE" recovery model in SQL Server:

This issue occurs because of an error in SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, or SQL Server 2014.

And the proposed solution was to install Cumulative Update 1 for SQL Server 2014

  1. Also this may be caused due to a corrupted index.

Possible solution: Try rebuilding indexes


Possible Workarounds

If the error is related to BULK INSERT method

(1) Using Microsoft Text Driver

SELECT * FROM OPENROWSET('MSDASQL',
'Driver={Microsoft Text Driver (*.txt; *.csv)};
DefaultDir=C:\Docs\csv\;',
'SELECT * FROM 001.csv')

(2) Using OLEDB provider

SELECT 
    * 
FROM 
OPENROWSET
        (
            'Microsoft.ACE.OLEDB.12.0','Text;Database=C:\Docs\csv\;IMEX=1;','SELECT * 
FROM 001.csv'
        ) t

References

  • How to import csv file with OPENROWSET?
  • T-SQL – Read CSV files using OpenRowSet
like image 184
Hadi Avatar answered Feb 13 '26 05:02

Hadi


Msg 0, Level 11, State 0, Line 0. A severe error occurred on the current command. The results, if any, should be discarded.

Look in the SQL Log for more details.

12.0.2000.

You are running an unsupported service pack level for SQL 2014. You should apply the latest service pack before doing much more troubleshooting of a problem like this:

  • How to obtain the latest service pack for SQL Server 2014
like image 44
David Browne - Microsoft Avatar answered Feb 13 '26 06:02

David Browne - Microsoft