sql日期时间溢出

发布于 2024-09-30 08:36:32 字数 909 浏览 0 评论 0原文

net,我试图将一行插入到实体中,但我不断收到以下错误:

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

这是我在 C# 端的代码:

        public static void DumpToLog(string s, string userID)
    {
        var ler = new LoggedExceptionRepository();
        var lex = new LoggedException();
        lex.loginID = userID;
        lex.dateTime = DateTime.Now;
        lex.text = s;
        ler.Add(lex);
        ler.Save();
    }

我尝试运行 sql server profiler,它执行的唯一操作是以下内容(如果我直接针对 sql server 执行,它会起作用!!):

    exec sp_executesql N'insert [dbo].[LoggedExceptions]([text], [loginID], [dateTime])
values (@0, @1, @2)
select [ID]
from [dbo].[LoggedExceptions]
where @@ROWCOUNT > 0 and [ID] = scope_identity()',N'@0 nvarchar(max) ,@1 varchar(50),@2 datetime',@0=N'payment failed, rv = 0',@1='riz',@2='2010-11-03 12:05:00:690'

关于我下一步可以做什么的任何建议?

net and I'm trying to insert a row into an entity, and I keep getting the following error:

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

Here's my code on C# side:

        public static void DumpToLog(string s, string userID)
    {
        var ler = new LoggedExceptionRepository();
        var lex = new LoggedException();
        lex.loginID = userID;
        lex.dateTime = DateTime.Now;
        lex.text = s;
        ler.Add(lex);
        ler.Save();
    }

I've tried running sql server profiler and the only thing it executes is teh following (which if I execute directly against the sql server, it works!!):

    exec sp_executesql N'insert [dbo].[LoggedExceptions]([text], [loginID], [dateTime])
values (@0, @1, @2)
select [ID]
from [dbo].[LoggedExceptions]
where @@ROWCOUNT > 0 and [ID] = scope_identity()',N'@0 nvarchar(max) ,@1 varchar(50),@2 datetime',@0=N'payment failed, rv = 0',@1='riz',@2='2010-11-03 12:05:00:690'

any suggestions as to what I can do next?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

公布 2024-10-07 08:36:32

如果对日期参数值进行硬编码,它会起作用吗?可能发生了其他事情,或者可能是误导性信息。

does it work if you hardcode the date parameter value? there could be something else going on, or it could be a misleading message.

风筝有风,海豚有海 2024-10-07 08:36:32

LoggedExceptions 中是否还有您未设置的另一个日期时间列?在某些情况下,框架将使用 DateTime.MinValue 来填充未指定的列。尝试为 LoggedExceptions 中的所有日期时间列设置显式值。

Is there another datetime column in LoggedExceptions that you're not setting? There are cases where a framework will use DateTime.MinValue to fill in unspecified columns. Try setting explicit values for all datetime columns in LoggedExceptions.

樱&纷飞 2024-10-07 08:36:32

发现了问题。我只是没有意识到我正在创建新对象并将它们分配给代码早期的现有实体。因此,当它保存数据上下文时,那些早期的实体出现了问题。

found the issue. I just didn't realize that I was creating new objects and assigning them to existing entities earlier in teh code. so when it was saving the datacontext, it was having a problem with those earlier entities.

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