sql datetime overflow
net 开发者_JAVA百科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?
does it work if you hardcode the date parameter value? there could be something else going on, or it could be a misleading message.
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.
精彩评论