Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Bulk Insert: Unexpected end-of-file (EOF) encountered in data file.


Bulk Insert: Unexpected end-of-file (EOF) encountered in data file.

Author
Message
Gerry Viator-350055
Gerry Viator-350055
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 82
Hi all,

Trying to bulk insert a csv file from a bcp command generated file but, get
this error:

Server: Msg 4839, Level 16, State 1, Line 3
Cannot perform bulk insert. Invalid collation name for source column 45 in
format file '\\MyServer\drive_e\temp\usage.fmt'.

First Column in Distination table is identity column and the table already
contains many rows. See below for DDL.

Bulk Insert Statment:

BULK INSERT Mytable FROM '\\MyServer\drive_e\temp\usage.csv'
WITH (DATAFILETYPE = 'Native',
TABLOCK,
BATCHSIZE = 100,
FORMATFILE = '\\MyServer\drive_e\temp\usage.fmt',
ROWTERMINATOR = '\n'


This is the format file:

8.0
45
1 SQLINT 0 12 "/t" 2 UsageID SQL_Latin1_General_CP1_CI_AS
.......
.......
43 SQLCHAR 1 10 "/t" 44 api_BillDate SQL_Latin1_General_CP1_CI_AS
44 SQLCHAR 1 50 "/t" 45 api_FileName SQL_Latin1_General_CP1_CI_AS
45 SQLCHAR 1 10 "\r\n" 46 AcctCode_new SQL_Latin1_General_CP1_CI_AS


this is the distination table:

CREATE TABLE [Mytable] (
[UsageRowID]int IDENTITY(1,1) NOT NULL ,
[UsageID]int NOT NULL,
........
........
[api_BillDate]char(10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[api_FileName]char(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[AcctCode_new]varchar(10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO


This is the bcp command that created the csv file:

DECLARE @bcpCommand VARCHAR(2000)
SET @bcpCommand = 'bcp "SELECT ..,...,..,.,...,... from Sometable" queryout
E:\temp\usage.csv -SMyServer -T -n -b 100'

EXECUTE xp_cmdshell @bcpCommand
go


thanks
gv
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45203 Visits: 39925

1. Don't use anything but SQLCHAR when importing text files.
2. Don't use anything but "" for coalation on non-character based columns.



--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Scott Coleman
Scott Coleman
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2944 Visits: 1417

Does the last line of your format file have a trailing CR/LF? Since it is complaining about the last field of the last line, I think this might be the problem. The last line should be terminated with a CR/LF, the file should not just end after the collation field.





Sinshith S Anand
Sinshith S Anand
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 163
Please check this link...all your doubts will be cleared

http://sinshith.wordpress.com/2010/04/12/bulkinsert-process/
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search