Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 BCP error message ( import text file)

Author  Topic 

korssane
Posting Yak Master

104 Posts

Posted - 2009-03-24 : 13:53:27
Hi All ,

i am trying to import a text file from the server using BCP but i am getting this specific error :

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

Here is my Code :

BULK
INSERT [Database-name].[dbo].[ImportTable]
FROM '\\Servername\File1.txt'
WITH
(
CODEPAGE='RAW',
FIRSTROW = 2,
FIELDTERMINATOR ='\t',
ROWTERMINATOR = '\n'
)
Go


Any suggestions will be greatly appreciated.

THanks

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-03-24 : 16:10:38
what des the content of File1.txt look like and what does the structure of ImportTable look like
Go to Top of Page

korssane
Posting Yak Master

104 Posts

Posted - 2009-03-24 : 16:44:19
The text file resides in the server and when i open it it looks like collumns with the 1st raw as a header.
of course i have specify in the code above to ignore the 1st raw.
The ImportTable has the same number of fields (39) all of them are set to "nvarchar(MAX) ".
Now, i know that is my file cuz i have tried to open another text file form another location and it worked fine.

Any suggestions ?

Thanks
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-03-24 : 17:10:21
Your file is not formatted correctly or you aren't using the correct terminators in the BULK INSERT command. Use a hex editor view the end of file character and end of row characters, correct them, and then try again.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

korssane
Posting Yak Master

104 Posts

Posted - 2009-03-25 : 08:47:56
Hi ,
this works when i removed the end of the file which was a square symbol.
The thing is : this file is automatically created every day.
Q1- is there a way to ignore the end of the file ?
Q2- Is there a way to run the query daily @ 08:00AM in order to update this table. ?

thank a lopt for the help.

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-25 : 08:51:13
Import the file content into a staging table first.
Then insert into original table from this staging table where (the column where the "square" is stored) <> CHAR(10) <-- or 13 depending which ascii value the "square" is.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

korssane
Posting Yak Master

104 Posts

Posted - 2009-03-25 : 08:58:33
Sorry,
i am not following you.

please, can you be more explicit.
The daily table is daily generated and i can not do change on it ?

Thanks
Go to Top of Page

korssane
Posting Yak Master

104 Posts

Posted - 2009-03-25 : 09:15:45
Hi ,
Here is the symbol in the end of the file "" . it is basically a square.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-03-25 : 15:46:34
Fix the process that creates the file, so that it is a valid file.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -