The other day I had the following problem. One of my test servers had been setup with US regional settings and should have been setup with UK settings.
The problem had been unnoticed for a while until our C# .Net application tried to call a stored procedure on a database on another server. This database server had UK regional settings. The stored procedure expected to get a date in UK ‘Long format’. The error message was a database error saying something like:
convertion error can't convert from NVarChar to DateTime
As the application was already compiled and being used on a live server I could not modify the code, I therefore had to run SQL Profiler and see what values were being passed into the stored procedure. This is where I saw the US ‘Long Date’ format being passed in.
.Net regional settings fix
So I tried changing the regional settings on my server back to the UK, but the application was still sending the US ‘Long Date’ value. I dug real deep and suspected that IIS was doing something funny and found further regional settings in an Advanced tab, but still this didn’t fix the issue.
The problem I soon discovered is that when you install the .Net framework it internalises the regional settings but when you try and change them on the server these internalised settings don’t get changed.
The only solution to this is then to modify the machine.config file.
The machine.config file is in each installation of the .Net framework. I happen to have both .Net 1.1 and .Net 2.0, however I changed the machine.config file in only the .Net 1.1 installation directory (even though our application is .Net 2.0) and all worked fine. The machine.config can be found in this directory:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\CONFIG
If you are using .Net 2.0 I’m sure you can make the same changes to the globalization XML node.
Please change the globalization XML node to have the correct cultural settings in our case en-GB:
<globalization
fileEncoding="utf-8"
requestEncoding="utf-8"
responseEncoding="utf-8"
culture="en-GB"
uiCulture="en-GB"
/>
To test that a .Net application would send the correct settings I wrote a simple test app which would print the ‘Long Date’ to the console. Here is the source code if you want to quickly test it yourself:
ShowLongDate.cs
using System;
namespace examples
{
class ShowLongDate
{
static void Main(string[] args)
{
DateTime current = DateTime.Now;
string longDate = current.ToLongDateString();
System.Console.WriteLine(string.Format(”Date as longDate: {0}”, longDate));
}
}
}
Interesting things I learned
You can open the regional settings from the commandline or from Start/Run by typing
intl.cpl
Also all the regional settings are located in the registry here:
HKEY_CURRENT_USER/Control Panel/International
Useful URLs: http://www.microsoft.com/globaldev/reference/localetable.mspx
Anyway I hope this helps if you have the same problem.
Hi Ben,
I happen to have exactly the same problem. We forgot to set the reginal Setting before we installed .NET 2.0 and 3.5. Now we want to switch from en-US to nl-NL, I have tried your solution but it won’t work. Is a machine restart needed?
Any other options you can think of?
Marc
Hi Marc
Try a restart, and check that the longname.exe app mentioned in the article works.
However if it is an IIS server I think there are some further settings that can be changed. Select properties on your IIS web site and look in the Advanced settings. I can’t quite remember where they are, and currently can’t check.
Hope that helps. BE…
Hya,I’m havint this issue has been driving me insane as well.
However I havent been able to fix it as iet, my main problem is if i run a console application when i’m logged on it works ok, whoever if i got a webservice that starts the console application the user [ Networ Service], for some reason run as American [ regional settings] even that i did all of the above, and should be running as Uk region setting………. Help..
tks
Jack