SqlDateTime 溢出。 2008年例外
我将默认日期(开始日期和结束日期)传递给 sp('1/1/1753 12:00:00 AM' 和'12/31/9999 12:00:00 AM')。
这在 2005 年工作正常,但在 2008 年出现“SqlDateTime 溢出。必须在 1/1/1753 12:00:00 AM 和 12/31/9999 11:59:59 PM 之间”异常。
情况就是这样当我从 Management studio 运行 sp 时,它工作正常,但在通过网站的实时服务器上却出现错误。
提前致谢
am passing default dates (startdate & enddate) to an sp as ('1/1/1753 12:00:00 AM' & '12/31/9999 12:00:00 AM').
This was working fine in 2005, but am getting "SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM" exception in 2008.
And the twist is such that when i run the sp from Management studio it works fine but on the live server through website it gives error.
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我同意 Ed Harper 的观点,即问题可能是不同环境之间的区域设置或语言设置差异。我不同意他的解决方案。
尽快将这些日期时间值放入 DateTime 变量中,并且不要将它们视为字符串。即在网站上执行此操作,然后依靠 ADO.Net 等将日期时间值正确编组到 SQL Server。更新存储过程以期望参数也为日期时间 - 基本上,在处理中尽早停止将它们视为字符串。
I'd agree with Ed Harper that the problem is likely to be locale or language setting differences between different environments. I'd disagree with his fix.
Get those datetime values into DateTime variables, as soon as possible, and don't treat them as strings. I.e. do that on the website, and then rely on e.g. ADO.Net to correctly marshal datetime values across to SQL Server. Update the stored proc to expect the parameters as datetimes also - basically, stop treating them as strings as early as possible in your processing.
这可能是安装操作系统的区域设置或链接到运行代码的用户帐户的区域设置的问题,因为不同的区域设置将您提供的格式的日期解释为
DD/MM/ YYYY
或MM/DD/YYYY
解决此问题的最佳方法是使用规范的日期格式 -
YYYY-MM-DDTHH:MM:SS AM/PM
、YYYYMMDD HH:MM:SS AM/PM
或YYYY-MM-DD HH:MM:SS(24h)
This is likely to be a problem with the locale in which the OS was installed or the locales linked to user accounts under which the code is running, because different locales interpret dates in the format you are supplying as either
DD/MM/YYYY
orMM/DD/YYYY
The best way to get around the issue is to use a canonical date format - either
YYYY-MM-DDTHH:MM:SS AM/PM
,YYYYMMDD HH:MM:SS AM/PM
orYYYY-MM-DD HH:MM:SS(24h)