SSIS, Locale and DT_Decimal

I.E 1 Reputation point
2021-01-22T16:15:21.213+00:00

In SSIS (2016) I'm reading a flatfile and converting a field containing decimals in a Swedish format ("0,5" - "1,22" etc) to DT_Decimal (with a scale of 2), resulting in 0.5, 1.22 as expected. However the source contains one misplaced value - "84.717.050". An error is produced ("The data value cannot be converted for reasons other than sign mismatch or data overflow.") when this value is encountered, and it can be redirected fine as an erroneous row in the dataflow. This is on my local client or development machine in Visual Studio, with Swedish region and regional formatting. Additionally, the package, connection manager, dataflow and flat file source are all set to LocaleID Swedish (Sweden).

The package is then deployed and executed on a server - where the service account executing the package through SQL Server Agent is set to Danish region and regional formatting. Here, the value "84.717.050" does not produce an error, instead it is converted to 84717050. This causes a problem later on in the destination as this is not an expected value.

The same behaviour is encountered if I change the Regional format to Danish on my machine, and execute the package in Visual Studio. The error is no longer produced when the value, "84.717.050", is encountered.

Experimenting and simplifying further, I created an expression task (with Swedish LocaleID in SSIS) with this formula:

(DT_DECIMAL, 2)"84.717.050"

This is producing 84717050,00 when using Danish Regional settings in Windows, but throws "Error code 0x80020005 occurred attempting to convert from data type DT_WSTR to data type DT_DECIMAL." with Swedish Regional settings.

I would assume that the LocaleID in SSIS should affect how decimals are interpreted, but instead the Windows Regional format setting seems to be used in this case. Is this really the correct and expected behaviour?

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,454 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Monalv-MSFT 5,896 Reputation points
    2021-01-25T07:40:59.95+00:00

    Hi @I.E ,

    The data type can be converted from DT_WSTR to DT_DECIMAL when the value in string is number.

    Please refer to Cast (SSIS Expression) and decimal and numeric (Transact-SQL).

    60126-error.png
    60077-success.png

    Best Regards,
    Mona

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Jim Young 1 Reputation point
    2021-01-29T17:28:24.167+00:00

    Rather than using the SSIS implied conversions, try running the data through a script task transform. There you can use the .Net Decimal.TryParse function to convert the string values using a locale specific format. Any failure can be sent to another output defined in the script.

    0 comments No comments