SSIS 2012 date formats dmy vs mdy

There are three SQL Servers:

  • PROD (2008 R2)
  • NEW_TEST (2012)
  • NEW_PROD (2012)
  • I am migrating a large number of SSIS packages from PROD to both NEW_TEST and NEW_PROD servers.

    Source data comes from flat text files

    Source DATE data is in the format of dd/mm/yyyy (ie 5th of November 2015 is stored as 05/11/2015).

    In SSIS, the definition of the DATE source column (text file) is Unicode string (DT_WSTR) and the target column (in DB table) data type is DATETIME so a type conversion happens between reading the data from text file and writing it into the DB table.

    When I run the package on the PROD (old) server, the data is loaded correctly.

    When I run the same (but upgraded to 2012) package on the NEW_TEST server, the data loads OK, too.

    However, when I run the package on the NEW_PROD server, the data loads incorrectly (ie 05/11/2015 is loaded as 11th of May 2015 instead of expected 5th of November 2015). So it seems that the NEW_PROD server somehow converts UK (DMY) source date string using US (MDY) settings.

    After spending a significant amount of time trying to understand what is going on, this is what I discovered:

  • NEW_PROD server has collation set to "SQL_Latin1_General_CP1_CI_AS"
  • NEW_TEST server has collation of "Latin1_General_CI_AS" - this matches the current PROD server so it seems that the collation on the NEW_PROD is incorrect.
  • There are no other differences between server settings at the server level except for the one above.
  • The target database has collation set to Latin1_General_CI_AS on both NEW_* servers as well as on the current PROD server
  • When I run the package manually on my local machine, the data is loaded CORRECTLY regardless of target.
  • When I run the package from a scheduled job on the NEW_PROD server, the data is loaded INCORRECTLY.
  • Now, an interesting thing: when I run the package from a scheduled job on the NEW_TEST server BUT with target connection pointing to the NEW_PROD server, the data loads CORRECTLY
  • On all servers, the user that runs the SSIS service has default language set to British (langid = 23 in sys.syslanguages). The same applies for the user that owns the scheduled job.
  • When I change the source data type definition in the SSIS package from DR_WSTR to DATETIME, the data is loaded CORRECTLY regardless of where the package is executed.
  • When I add a data transformation between source and target, transforming that one column from DT_WSTR to DB DATETIME, the data loads INCORRECTLY on NEW_PROD but still runs ok on the NEW_TEST.
  • I am trying to figure out how to make the data load correctly on the NEW_PROD server, using scheduler, without:

  • rebuilding its master database with the correct collation (impractical - too many databases, too much data)

  • changing source data type from DT_WSTR to DATETIME on all date columns in all SSIS packages (too many of them plus they work fine on the other two servers)

  • changing target data type (in the DB table) from DATETIME to VARCHAR(...)

  • So, long story short, I am trying to understand which element of the process is responsible for interpreting the source string as date and how to make it use DMY instead of MDY regardless of the incorrect collation setting. I thought I got it but then item 7. on the above list got me puzzled again.

    Any faintest hints?


    There are 4 places to check when dealing with date interpretation issues in SQL Server 2012:

  • Collation of the db (initially inherited from server collation)

  • SSIS language setting (LocaleID property at the package level)

  • Regional settings of the user executing the package (at OS level on the server where the package is executed)

  • Language setting of the database login associated with the execution context (the "Default language" property of a login)

  • There are probably priorities between them but I just set them all to the same value and the issue is now gone.

    链接地址: http://www.djcxy.com/p/89088.html

    上一篇: 反应FixedDataTable响应行/单元大小

    下一篇: SSIS 2012日期格式dmy vs mdy