实体框架-SQL Server 2005-IIS服务器日期时间问题 [英] Entity Framework - SQL Server 2005 - IIS Server datetime issue

查看:88
本文介绍了实体框架-SQL Server 2005-IIS服务器日期时间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MVC3和Entity Framework。在我的应用程序中,我需要通过EF调用SQL Server 2005中的存储过程,以根据传递的 datetime 参数搜索某些数据。



在本地环境中,一切似乎都可以正常工作。但是在将其托管到IIS之后,尝试从日期 2012年8月13日(我想SQL中的13就是一个月)进行搜索时,我遇到了异常



错误提示


SqlDateTime溢出。必须介于1/1/1753 12:00:00 AM和
之间12/31/9999 11:59:59 PM


我理解错误是由于 System.Datetime SqlDatetime 之间的日期时间格式不同。 p>

但是我不明白为什么它在使用相同SQL Server但在IIS服务器中托管后出现此错误的本地环境中没有任何问题。



此问题是否有解决方法?

解决方案

我的问题现在已解决。问题出在IIS中的区域性设置。
我已经将这些行添加到我的应用程序web.config中,并且现在可以正常使用。

 <全球化requestEncoding = utf-8 responseEncoding = utf-8 culture = zh-CN uiCulture = zh-CN /> 

有关更多信息,请查看此问题与IIS中的文化设置有关


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

这篇关于实体框架-SQL Server 2005-IIS服务器日期时间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆