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

  • Home
  • SEARCH
  • 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 617067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:23:40+00:00 2026-05-13T18:23:40+00:00

I want to use BCP to load into a SQL Server 2005 table with

  • 0

I want to use BCP to load into a SQL Server 2005 table with an nvarchar field using a loader control file. As I understand it, SQL Server 2005 only supports UTF-16 (and I believe it is UTF-16 LE). The file is being output by a Java program. The way I have it currently set up is as follows:

  1. An XML format BCP loader file (created using the following command:
    bcp test_table format nul -c -x -T -f test_table.xml -S server)

  2. A Java program using the following code to write the output:

    File f = new File("from_java.txt");
    String encoding = "x-UTF-16LE-BOM";
    OutputStream os = new FileOutputStream(f);
    OutputStreamWriter outputStreamWriter = new OutputStreamWriter(os, encoding);
    String theString = "áááááLittle Endian, BOM\r\n";
    outputStreamWriter.append(theString);
    outputStreamWriter.flush();
    outputStreamWriter.close();
    
  3. Then using the following bcp command:
    bcp test_table in from_java.txt -T -f test_table.xml -S server -error error.txt

What I get in the table is ÿþá. and not áááááLittle Endian, BOM

I’ve tried a few different permutations of changing parameters:

  • changing the way I generate the loader control file (using -n for native data instead of -c for character data…I think this may have something to do with it, but I didn’t see any improvement in my inserted data)
  • tried several different forms of the UTF-16 encoding, including big endian and little endian with no BOM, to no avail
  • tried to output the BOM manually in the file as I read somewhere that Microsoft really like to make use of BOM information
  • looked into trying to output the file as UCS-2 (instead of UTF-16) as that is (apparently) what BCP is actually reading the file in as
  • tried -w on the bcp import, this does work, but not in conjunction with a loader format file (is there a way to incorporate whatever magic tells BCP that the file is encoded in UTF-16 into the format file?)
  • I can get it to work if I output the file in windows-1252 and specify that codepage as a -c 1252 option to bcp when I load the file (but I don’t want to do this as I will be losing information as UTF-16 is a superset of what can be represented compared to 1252)

Has anyone managed to get bcp to load into an nvarchar field using UTF-16 data in conjunction with a loader format configuration file?

Thanks in advance,

-James

  • 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. Editorial Team
    Editorial Team
    2026-05-13T18:23:40+00:00Added an answer on May 13, 2026 at 6:23 pm

    I have been literally underwhelmed with responses, but I have cracked it.

    The loader file needs to be generated with a -w flag, so the command to generate the file is:

    bcp <table> format nul -w -x T -f loader-control-w-format.xml -S <server> -t "||"

    This leads to a loader control file that looks a little different, you get entries such as:

    <FIELD ID="1" xsi:type="NCharTerm" TERMINATOR="|\0|\0" MAX_LENGTH="1000" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>

    Note the delimiter is listed as |\0|\0, the zeroes correspond to the extra byte in the file as UTF-16 (or just “unicode” as Microsoft (wrongly) call it) is a double byte character encoding.

    Some notes for the sanity of anyone else dealing with BCP in this way:

    • When SQLServer talks of “native” they mean native characters, i.e. accented characters
    • When SQLServer talks of Unicode, what they actually mean is the UTF16 (Little Endian) manner of encoding the Unicode characterset. This is what the -w pertains to
    • When writing a file for loading into BCP using UTF-16, the file has to be in UTF-16 Little Endian format, and cannot contain a UTF BOM (as BCP will interpret this a byte that should be loaded and your first record will contain the BOM, urgh!)

    The Java code for writing out a file in UTF-16 that can be loaded in this way is as follows:

        final File f = new File("C:\\temp\\bcp_prob\\from_java-UTF-16.txt");
        //LE with no BOM is important here:
        final String encoding = "UTF-16LE";
        final OutputStream os = new FileOutputStream(f);
        final OutputStreamWriter outputStreamWriter = new OutputStreamWriter(os, encoding);
        final String theString = "UTF-16-LE, intermetálico básicos intermetálico película magnética dinámicos||another_col\r\n";        
        outputStreamWriter.append(theString);
        outputStreamWriter.flush();
        outputStreamWriter.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 378k
  • Answers 378k
  • 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 Because of this: First you create an array with zero… May 14, 2026 at 9:22 pm
  • Editorial Team
    Editorial Team added an answer I assume this question is about HTML forms. From the… May 14, 2026 at 9:22 pm
  • Editorial Team
    Editorial Team added an answer This is usually done with something called a stack frame.… May 14, 2026 at 9:22 pm

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.