SqlDateTime Error!!!

Feb 8, 2011 at 3:12 PM

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

I've tried to add a datetime column to my EventPart everything seems to be correct and by submitting the form, EventPart's date fields are update pretty fine inside the Driver Editor function, but It causes the following error!

It seems I only have this problem when I want to add new Items, and I don't get this error for Updating existing Items!!!

It's super Urgent, and any helps could save my life ;)!


Feb 8, 2011 at 3:41 PM

Oh noes! In 1753, they'd probably make you walk the plank! Yarrrrgh!

Feb 8, 2011 at 5:59 PM

You are probably not initializing the DateTime field in the Record before saving to the database (i.e. Orchard ends up trying to insert an invalid date). If the date is really optional, i think making the field "Nullable" (DataTime? MyDate) will solve the issue.

Feb 8, 2011 at 7:36 PM

I've changed the Date Columns to Nullable, and It works fine now!

But, what was the problem with NotNull DateTime columns?! Please take a look Maybe thats a bug!

Apr 3, 2012 at 5:35 PM

I've just been battling with this same problem and here's what I've discovered.  I'll use EventPart as an illustration

I was surprised, because my 'EventPart' equivalent (inheriting from ContentPart<EventRecord>) had data validation on it, so it couldn't save it with an out of range date.  Yet I still got this error.

I discovered however, that when Orchard creates the new ContentItem (perhaps an Event type with an EventPart), the Part Record is inserted into the database with a new instantiation of the relevant ContentPartRecord class, and then updated to the value set in the driver.

DateTime is initialised with DateTime.MinValue (which is out of range for SQL Server), so this is the default value of the relevant property on the Record class.  And since this could not be translated to null when it inserted into the database, the out of range error comes up.  It does not matter that the 'insert' statement is immediately followed by an update statement with the correct, initialised values, the insert fails.

I worked around this by adding a constructor to my ContentPartRecord class, which set a default date.  Since the ContentPart has validation on it, this should be overriden by the ContentPart with the correct date, so for everything else it is irrelevant, but it makes NHibernate and SQL server happy.

Apr 3, 2012 at 6:02 PM

I've filed this as a bug : http://orchard.codeplex.com/workitem/18604