SqlDateTime 溢出。 2008年例外

发布于 2024-11-06 18:15:34 字数 270 浏览 0 评论 0原文

我将默认日期(开始日期和结束日期)传递给 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北风几吹夏 2024-11-13 18:15:34

我同意 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.

初相遇 2024-11-13 18:15:34

这可能是安装操作系统的区域设置或链接到运行代码的用户帐户的区域设置的问题,因为不同的区域设置将您提供的格式的日期解释为 DD/MM/ YYYYMM/DD/YYYY

解决此问题的最佳方法是使用规范的日期格式 - YYYY-MM-DDTHH:MM:SS AM/PMYYYYMMDD HH:MM:SS AM/PMYYYY-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 or MM/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 or YYYY-MM-DD HH:MM:SS(24h)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文