Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 184275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:15:49+00:00 2026-05-11T15:15:49+00:00

I am trying to import some data to SQL Server 2008 by means of

  • 0

I am trying to import some data to SQL Server 2008 by means of Bulk Insert, but I’ve been getting a ton of conversion errors:

Msg 4864, Level 16, State 1, Line 1 Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 5902, column 2 (Type).

OK so first things first:

a) the data comes from a parser i built in C#. In this file, there are 4 columns, separated by tabs. The columns may or not be null. The collation is UTF-8. Here’s an excerpt of it.

D00486  DBLinks PubChem 7847552 D00486  DBLinks LigandBox   D00486 **D00487    Name        Pyridostigmine bromide (JP15/USP/INN)** -- WORKS D00487  Name        Mestinon (TN) D00487  Chemical    260.016 C9H13N2O2. Br D00487  Target  PATH:hsa00564(43) D00487  Remark      Therapeutic category: 1239 D00487  Remark      ATC code: N07AA02 D00487  Pathway PATH: map07220  Cholinergic and anticholinergic drugs D00487  DBLinks CAS 101-26-8 D00487  DBLinks PubChem 7847553 D00487  DBLinks DrugBank    DB00545 D00487  DBLinks LigandBox   D00487 **D00488    Name        Pyrimethamine (JAN/USP/INN)** -- DOES **NOT** WORK! D00488  Name        Daraprim (TN) 

The second to last row generates an error message like the one i’ve previously shown you. What really amazes me is that the other line i’ve placed on bold is quite similar yet does not generate any error whatsoever.

b) This is what i’m using to create the table:

CREATE TABLE [dbo].[KB] ([BEName] [nvarchar](1000) NOT NULL, [Type] [nvarchar](1000) NULL, [Name] [nvarchar](1000) NULL, [Value] [nvarchar](1000) NULL) ON [PRIMARY] 

c) This is what i’m currently using to import the data from a file:

DECLARE @SQL nvarchar(4000) SET @SQL = 'BULK INSERT KB FROM ''C:\KB.xml'' WITH (FirstRow = 1, FORMATFILE = ''C:\out_KB.fmt'')'; EXEC(@SQL) 

I had to manually generate the fmt file because for some reason BCP could not connect to my database (still working out the basics on it…) so it may be possible that it’s not as it should be. Either way, here are it’s contents:

9.0 4 1 SQLCHAR 0 100 '' 1 BEName SQL_Latin1_General_CP1_CI_AS 2 SQLCHAR 0 500 '\t' 2 Type SQL_Latin1_General_CP1_CI_AS 3 SQLCHAR 0 500 '\t' 3 Name SQL_Latin1_General_CP1_CI_AS 4 SQLCHAR 0 500 '\n' 9 Value SQL_Latin1_General_CP1_CI_AS 

As i’ve previously stated, i don’t have much experience with BCP; initially, I was simply using

BULK INSERT KB FROM ''C:\KB.xml'' WITH (FirstRow = 1, RowTerminator = ''\n'' , FieldTerminator = ''\t'') 

but it wouldn’t work anyway. I’d still rather use this instead of the FMT file; I googled and tried a couple of tricks (such as swapping \n with \n\cr or introducing the ASCII code of the \n instead).

Any ideas? I can’t say that i have’em, i’m exhausted right now, going to sleep until noon or something :S (it’s 4 AM here now).

Cheers mates, thanks and advance Hal

PS: I think the samples are ok, but please be my guest and request what you may need at any time. PS2: Sorry for the wall of text 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T15:15:49+00:00Added an answer on May 11, 2026 at 3:15 pm

    Non-XML bulk-insert files are very finicky. I looked at yours and don’t see a problem, but it is easy to miss problems.

    XML bulk-insert files are a lot easier to work with. Can you refactor your code to produce XML bulk insert files instead? I have also found that you must also use XML format files when using XML insert files, and BCP won’t create that for you — you have to write your XML format file yourself, but it’s pretty easy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 82k
  • Answers 82k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should be able to just use command substitution, using… May 11, 2026 at 4:37 pm
  • Editorial Team
    Editorial Team added an answer I think you'd be using a very poor soundcard if… May 11, 2026 at 4:37 pm
  • Editorial Team
    Editorial Team added an answer I think the answer to both your questions is No.… May 11, 2026 at 4:37 pm

Related Questions

I know this isn't a unique issue but I've not had much luck finding
I am trying to use the getJSON function in jQuery to import some data
Hi I am trying to learn Linq, so I am not sure if this
I am trying to create a website where I host my data on google
In C++ program, I am trying to #import TLB of .NET out-of-proc server. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.