how can I strip unprintable ascii characters from a flat file transformation in ssis

Jeff Franken 0 Reputation points
2025-09-29T21:41:51.41+00:00

I am loading a flat file to another flat file with headers. the source file has rows with unprintable ascii characters. I need to strip those out. it is giving truncation errors as the characters are making it think the field is too long. what is the simplest/easiest way to get those out of there?

SQL Server Integration Services
{count} votes

2 answers

Sort by: Most helpful
  1. Yitzhak Khabinsky 27,091 Reputation points
    2025-09-30T11:33:55.46+00:00

    Hi @Jeff Franken,

    As @Viorel mentioned, maybe "Unprintable ASCII characters" are needed. In such case you could try to change (1) Locale, (2) Code page, or (3) Unicode settings which are properties to a file in a Flat File Connection Manager Editor. Please see below.

    As an alternative, you can use SSIS Derived Column Task, and use REPLACE() function in its Expression.

    For the reference: https://learn.microsoft.com/en-us/sql/integration-services/expressions/replace-ssis-expression?view=sql-server-ver17

    SSIS Flat File Connection Manager 09-30-2025_01

    0 comments No comments

  2. Akhil Gajavelly 875 Reputation points Microsoft External Staff Moderator
    2025-10-13T10:29:10.2533333+00:00

    Hi @Jeff Franken,

    You can handle this directly within SSIS by adding a Script Component Transformation to clean your data before writing it to the destination flat file. This ensures all unprintable ASCII characters are safely removed and prevents truncation issues.

    1. Add a Script Component in your Data Flow and select it as a Transformation.
    2. Connect your source to the Script Component.
    3. Select the columns you want to clean as input columns.
    4. In the script editor, add the following code inside the Input0_ProcessInputRow method:
    5. public override void Input0_ProcessInputRow(Input0Buffer Row)
    6. {
    7.     if (!Row.MyColumn_IsNull)
    8.     {
    9.         // Remove all non-printable ASCII/control characters
    10.         Row.MyColumn = new string(
    11.             Row.MyColumn.Where(c => !char.IsControl(c)).ToArray()
    12.         );
    13.     }
    14. }

    Replace MyColumn with your actual column name

    1. Save, close, and re-run your package.

    Thanks,
    Akhil.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.