views:

161

answers:

3

My .Net .exe is used to read a file and store information in sql DB. On the dev system we had default setting and files in US locale and things were working fine.

I used the same .exe and deployed on to our Prod server where the default setting and files are in UK locale.

I have used the Datetime.Parse which should be parsing the date in the format of local system i.e for US MM/dd/yyyy and for UK dd/MM/yyyy.

But while parsing the date in UK format it gives an exception, Can someone help me out where am I doing wrong.

I also noticed something strange that when I changed the default setting of dev machine to UK and then compiled the .exe and deployed the same it worked.

Can you also let me know why did it worked.

+1  A: 

you have to supply an iformatprovider (i.e. an instance of a System.Globalization.CultureInfo) to your DateTime.Parse() method. btw, i suggest using TryParse or if you exactly know how your datetime strings arrive, use TryParseExact as they are much faster.

Joachim Kerschbaumer
A: 

The best solution is to specify the locale in the app.config, overriding the machine's.

Pablo Marambio
How is that the best for UK customers? Easiest maybe.
Henk Holterman
well... you have a point. Ups!
Pablo Marambio
A: 

Hard to say without more details, but maybe the application server and the sql server ran on another language setting than you expected. Even when you got the culture setting on the application server right, the date time formats on the sql server still are not as expected.

Theo Lenndorff