SSIS / BIDS Nvarchar Flat File Export Issue - Text was truncated or one or more characters had no match in the target code page

Posted on 2012-09-07
Last Modified: 2013-11-18
I'm having an issue with SQL Server 2008R2 64-bit with a BIDS Data Flow Task specifically.

I'm trying to export data from a SQL Server database to a flat file. I have narrowed the problem down to one specific field, which is type NVARCHAR(100) .

I altered my query to only include records that are a problem:


This allowed me to lower the record count to 160 records.
Then I used the 'TOP' command to get as many records to work as I could, which narrowed it further to the following 3 records which cause the problems (I pasted them and included a screen shot).

пѿсѿовой - Innovate

My flat file settings look like this:
flat file settings
And the column in question is set as such in the flat file connection manager:

DataType: Unicode String [DT_WSTR]
width 100
textQualifed: True

When I hit run, I get this message:

[Flat File Destination [19]] Error: Data conversion failed. The data conversion for column "NumAtCard" returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.".

I have tried the following:
1. Setting the column width to 250 in the advanced tab in the flat file manager
2. Setting TextQualified to False
3. Changing the column type to DT_String , DT_Text, and DT_NText

If I ignore these 3 records, everything works perfectly for all records in the table (100,000+). It's obviously an encoding problem, but I can't figure out how to fix it.

Question by:Candidochris
    LVL 16

    Accepted Solution

    You have some weird character in there somewhere! I'd recommend this:

    Go to IDM solutions - - and download a copy of UltraEdit for your OS (there are versions for Windows, Mac, and Linux).

    Install it (there's a trial period of a few weeks), and load in your CSV file

    Once you have the file up and you've found the problem line, switch to Hex mode - either Ctrl+H or Shift+Ctrl+H, depending on the version) and look at what you're <i>really</i> sending to SSIS, as opposed to what your normal text editor tells you it thinks you want to see!

    I think you'll see some strange characters in there that you really don't want to have! That's my opinion because your screenshot and paste are different!



    Author Comment

    Thanks, I will try UltraEdit - but the problem is that the characters are in the database - I'm looking for a way to ignore/convert these characters, regardless of what they are to generate the flat file.
    LVL 16

    Expert Comment

    Ah! Sorry - for some reason I was thinking you were importing.

    Try doing something like this:

    select * from tablename where field like '%[^!-}]%'

    which means "like any number of characters, a special char, and any number more, where the special char is outside the range from "!" (21 hex, 33 decimal) to "}" (7D hex)"

    For the character ranges check

    I didn't try, but you should be able to use the char function, so replace "!" with char(33), or use char(32) if you have spaces you want to ignore.



    Author Comment

    Thanks Mike, that's what I needed.
    LVL 16

    Expert Comment

    Great. I'm sorry for the long delay!

    So what's next? :)


    Author Comment


     Hopefully everything just works - but like always, I'll post in here if not. I did get this project going and working consistently.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
    How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
    The viewer will learn how to count occurrences of each item in an array.
    HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now