×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

FormatFile could not be read

FormatFile could not be read

FormatFile could not be read

(OP)
SQL Server 9.0

I'm attempting to import data from a CSV file with double quotes around each filed. I created a formatfile and placed it in the same directory the CSV file is located. I have load files from this directory before, but without a formatfile. This is the error I receive in sql server.

Msg 4862, Level 16, State 1, Line 5
Cannot bulk load because the file "\\mylocation\ffLeads.txt" could not be read. Operating system error code (null).

I am assuming this is not an error within my formatfile since it doesn't seem like it gets to that point???

RE: FormatFile could not be read

(OP)
Should have mentioned that I am using the BULK INSERT command.

BULK INSERT ##TEST FROM '\\myLocation\myfile.csv' WITH
(  
 FORMATFILE = '\\mylocation\ffLeads.txt'
)

RE: FormatFile could not be read

What output do you get when you run this?

exec xp_fileexist '\\myLocation\myfile.csv'

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom

RE: FormatFile could not be read

(OP)
I ran this command against the csv file and the format file.

File Exists = 1
File is a Directory = 0
Parent Directory Exists = 1

...for both files.

RE: FormatFile could not be read

(OP)
This is an example of my formatfile:

9.0
27
1  SQLCHAR  0  50  "','"  1  ID  SQL_Latin1_General_CP1_CI_AS
2  SQLCHAR  0  50  "','"  2  Fname  SQL_Latin1_General_CP1_CI_AS
3  SQLCHAR  0  50  "','"  3  Lname  SQL_Latin1_General_CP1_CI_AS
...

RE: FormatFile could not be read

(OP)
Sorry for the multiple post.  Here is a better example:

9.0
27
1  SQLCHAR  0  50  "','"  1  ID  SQL_Latin1_General_CP1_CI_AS
2  SQLCHAR  0  50  "','"  2  Fname  SQL_Latin1_General_CP1_CI_AS
3  SQLCHAR  0  50  "','"  3  Lname  SQL_Latin1_General_CP1_CI_AS
...
27 SQLCHAR  0  8  "'\r\n"  27  ConvertedDate  SQL_Latin1_General_CP1_CI_AS


Data Example:
"1","Bill","Jones","01012001"

RE: FormatFile could not be read

exec xp_fileexist '\\mylocation\ffLeads.txt'

Sorry... I meant to have you run this on the format file.

Also... I've seen format files get weird because of the lst line in it.  I don't remember which way it's supposed to be, but, I think there should NOT be any blank lines at the end of the format file.  Open it in notepad, go the end of the file (end of the last line) and hit backspace until the cursor is at the end of the line with text on it.

Ex:

CODE --> Good

9.0
27
1  SQLCHAR  0  50  "','"  1  ID  SQL_Latin1_General_CP1_CI_AS
2  SQLCHAR  0  50  "','"  2  Fname  SQL_Latin1_General_CP1_CI_AS
3  SQLCHAR  0  50  "','"  3  Lname  SQL_Latin1_General_CP1_CI_AS

CODE --> bad

9.0
27
1  SQLCHAR  0  50  "','"  1  ID  SQL_Latin1_General_CP1_CI_AS
2  SQLCHAR  0  50  "','"  2  Fname  SQL_Latin1_General_CP1_CI_AS
3  SQLCHAR  0  50  "','"  3  Lname  SQL_Latin1_General_CP1_CI_AS
      <-- eventhough this is blank, the line shouldn't be here.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom

RE: FormatFile could not be read

(OP)
I checked for extra lines and spaces. Everything is clear there.  I even tried to strip my csv file down to 1 row and 3 columns and the same changes to my format file.

RE: FormatFile could not be read

(OP)
That FAQ is great.  Star to that person.  Lesson learned; check out the FAQs, the solutions/suggestions are there for a reason.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close