Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having an issue with BCP Command

Status
Not open for further replies.

VIJSQL01

Programmer
Oct 30, 2010
74
US
hi,

I am trying to load a table in SQL 2008 by using a data present in .csv file by using BCP command. I am unable to do this, as it is throwing following error.

Code:
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 15. 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)".

But as an workaround, i opened the same file in excel and saved as .csv again from my end. After doing this, i am able to load the data to my table.

I dont understand, why the hell it should throw an error message, when i am trying to load the data initially. Why is not, second time. The file which i am trying to load for the first time, is the Output of SAS program, which is run with Linux OS.

Can you please help me to identify this problem? what am i doing wrong here?

Thanks in advance for your help.





 
Hi,
in Linux and other Unix-like OSes a line is terminated by linefeed (\n), in Windows by Carriage return + Linefeed (\r\n). When you opened the file with Excel and saved it again the line terminators were changed to the format Windows-utilities expect.
You'll have to create a format file for bcp that specifies the row terminator as \n to overcome this issue.
 
hi,

Thanks for the reply. Unfortunately, my issue is not yet resolved with the solution provided.

Infact, i am already using-
Code:
\n
as the line terminator. I am giving you the BCP command which i am using for the loading, for your reference. Hope, this will help you to look into the problem more specifically.
Code:
SET @SQLBulkInsert_State = 'BULK INSERT dbo.REAS_State_BE FROM ''\\10.48.164.48\Datamove1\REAS_QA_DATA\REAS'+substring(@ProcessingMonth,3,4) +'\HPI_Bulk_Export_by_STATE_'+substring(@ProcessingMonth,1,6)+'.csv'' 
WITH (FirstRow = 1, FIELDTERMINATOR = '','''+',ROWTERMINATOR = ''\n'''+')'

As always, thanks for providing the help.
 
between, i was wondering, according to above suggestion, how to create format file for bcp command?
Can anybody throw some light on this?
 
Thank you. one more help please.[smile2].....i am little confused, which option to use among the below. I have .csv file to load the data and the data types are varchar in the table.

A. Creating a non-XML format file for native data

B. Creating a non-XML format file for character data

C. Creating a non-XML format file for Unicode native data

D. Creating a non-XML format file for Unicode character data
 
hi ,

i am using following syntax to create a format file.

Code:
bcp REAS.REAS_STATE_BE_LinuxTest format nul -c -x -f someFile..xml -T

But its throwing me following error. i dont understand. please help.
Code:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '.'.
 
Does your filename need to be in quotes? I have not done this for a while so I do not remember.

djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top