Xerratus
Happily stressed out, since 1974


 
Sunday, August 03, 2008
<< Fix for invalid character in sproc calling sp_xml_preparedocument that has valid vs.NET xml

Over the weekend I helped launch a website that was located in the US but opted to host the site on a Canadian dedicated server.  One of the first things I did while setting up the server was to change the regional settings from "en-CA" to "en-US" (control panel -> regional and language options).  After pushing the site up to the server, I noticed during my testing that everywhere I was displaying dates (using the built-in .ToLongDateString() function of the DateTime object), the incorrect format was showing up.  Further more, transaction dates were being entered into the database incorrectly as well.

en-CA formats:

Short date: "dd/MM/yyyy"
Long date: "MMMM-dd-yy"

en-US formats:

Short date: "M/d/yyyy"
Long date: "dddd, MMMM dd, yyyy"

So, the computers region was setup correctly but the incorrect dates were still being shown.  Since the dates were being driven by a .NET object, I next looked at the .NET Framework (I'm running 2.0).  The solution I found was to modify the globalization element of the web.config by adding the following to the <system.web> element:

<globalization
   fileEncoding="utf-8"
   requestEncoding="utf-8"
   responseEncoding="utf-8"
   culture="en-US"
   uiCulture="en-US"
/>

Furthermore, since this was a dedicated server and all of the sites were going to be US sites we moved this from the web.config to the machine.config so that all new sites would not run into this problem.