1
votes

I have an csv like this :

"F","003","abc""X","1","50A1","name","Z5AA1A005C","70008","","A1ZZZZ17","","","","","","""X","2","50A1","name","Z5AA1A005C","70007","","A1ZZZZ17","","","","","","""X","3","50A1","name","Z5AA1A005C","70000","","A1ZZZZ17","","","","","",""

I need to bulk insert to tabel A from the 2nd row

BULK INSERT A FROM 'c:\csvtest.csv' 
  WITH
  ( 
   FIELDTERMINATOR='","',
   ROWTERMINATOR='0x0a',
   FIRSTROW = 2,
   DATAFILETYPE = 'widenative'
  )

the problem is when I insert, failed insert it show error :

Msg 4866, Level 16, State 8, Line 15 The bulk load failed. The column is too long in the data file for row 1, column 15. Verify that the field terminator and row terminator are specified correctly. Msg 7301, Level 16, State 2, Line 15 Cannot obtain the required interface ("IID_IColumnsInfo") from OLE DB provider "BULK" for linked server "(null)".

I have tried rowterminator : '0x0a','\n','\r\n','char(10)' but nothing works

2
What is the row terminator in your data? Have you tried \r as a terminator? \n is the default terminator for this command. \r is used in Linux systems - Panagiotis Kanavos
for now using '0x0a' - Mike
I don't think you can use a hex value as a terminator. If the source system is Unix/Linux, you should try \r, not `n`. - Panagiotis Kanavos
but \r not work either, the bulk insert failed to read rowterminator - Mike
PS: Was the edit accidental? You now show a single, very long line, whose third value contains a double quote. What does the file contain? - Panagiotis Kanavos

2 Answers

0
votes

Although it will only be inserting data from row2 row 1 still needs to be in the correct format as I'm pretty sure SQLServer performs a 'pre-validation' cycle against the Schema to ensure you have half a chance of the data getting to the database. Row 1 fails this 'pre-validation' because you have not provided all the columns as per the table schema.

0
votes

Try to Open the file in Notepad then check it for line structure and save it again.