简体   繁体   中英

Entity Framework - SQL Server 2005 - IIS Server datetime issue

I'm working with MVC3 and Entity Framework. In my application I need to call a stored procedure in SQL Server 2005 via EF to search for some data according to datetime parameters passed.

Everything seems to be working fine in local environment. But after hosting it into IIS I am getting an exception while trying to search from date 13-08-2012 (13 is taking as month in SQL I guess)

Error says

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM

I understood error is because of the difference between date time formats between System.Datetime and SqlDatetime .

But I didn't understand why it is working without any issues in my local environment which uses same SQL Server but getting this error after hosting in IIS server.

Is there any workaround for this issue?

My issue is resolved now. Issue was with the culture settings in IIS. I've added these line to my applications web.config and it is working fine now.

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

For more information check out this Issue with culture settings in IIS

IT depends on the culture of the server, you can format your culture with invariant format, on your date 13-08-2012, it consider 13 as month.

//Here an example of formatting with invariant culture
CultureInfo yourCulture = CultureInfo.InvariantCulture;
yourValue.ToString("yourFormat",yourCulture));

Verify that the date time formatting. Also, DateTime doesn't have the same range as SqlDateTime . You'll run into trouble if you receive an empty value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM