We help IT Professionals succeed at work.

BULK INSERT - Unexpected end-of-file (EOF) encountered in data file.

batchakamal
batchakamal asked
on
Medium Priority
7,228 Views
Last Modified: 2011-08-18
Hello Experts,

I have a BULK INSERT statement,

SET ANSI_WARNINGS OFF
bulk insert temp_SSI05AUG01_TXT from 'F:\SSI.TXT' with (FORMATFILE = 'C:\FormatFile\SSI.fmt' ,
FIRE_TRIGGERS, ROWS_PER_BATCH=1000)

and my format file SSI.fmt is,

8.0
2
1      SQLCHAR      0      15      ";"      1      Col1      Latin1_General_CI_AI
2      SQLCHAR      0      30      "\n"      2      Col2      Latin1_General_CI_AI

and my data file SSI.TXT is,

9132551868629;20050731 11:05:26
9132551868814;20050731 22:29:32
9132551784225;20050731 13:33:20
9132551785466;20050731 09:57:55
9132551376501;20050731 14:15:19

When I execute the above statement, I am getting the following error,

Server: Msg 4832, Level 16, State 1, Line 1
Bulk Insert: Unexpected end-of-file (EOF) encountered in data file.
Server: Msg 7399, Level 16, State 1, Line 1
OLE DB provider 'STREAM' reported an error. The provider did not give any information about the error.
The statement has been terminated.

Please give me an answer.


Comment
Watch Question

Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009

Commented:
is F: a local drive or not?
does the data file have some empty lines at the end?
does the data file a \n or rather a \r\n
batchakamalAdvisor

Author

Commented:
Thanks for ur reply.
Yeah I have checked the data, It has a summary line and empty line,
which look like this,

9132551868629;20050731 11:05:26
9132551868814;20050731 22:29:32
9132551784225;20050731 13:33:20
9132551785466;20050731 09:57:55
9132551376501;20050731 14:15:19
Total records : 8565

I have removed the last 2 lines, and it works fine.
Can I specify this one in the BULK INSERT statement itself. Bcoz i have n number of files, and also I am putting this BULK INSERT in the scheduled job for new files to upload.

Awaiting ur reply.

Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009
Commented:
unfortunately, on bulk insert you can only skip the first lines.
however, you can specify to allow X errors, using MAXERRORS

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_impt_bcp_2e5s.asp

SET ANSI_WARNINGS OFF
bulk insert temp_SSI05AUG01_TXT from 'F:\SSI.TXT' with (FORMATFILE = 'C:\FormatFile\SSI.fmt' ,
FIRE_TRIGGERS, ROWS_PER_BATCH=1000, MAXERRORS=2)

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.