sql日期时间溢出
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果对日期参数值进行硬编码,它会起作用吗?可能发生了其他事情,或者可能是误导性信息。
does it work if you hardcode the date parameter value? there could be something else going on, or it could be a misleading message.
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.发现了问题。我只是没有意识到我正在创建新对象并将它们分配给代码早期的现有实体。因此,当它保存数据上下文时,那些早期的实体出现了问题。
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.