This is a migrated thread and some comments may be shown as answers.

DateTime overflow exception

2 Answers 74 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Erik
Top achievements
Rank 1
Erik asked on 14 Dec 2011, 09:18 AM
Hi all,

Every once in a while (completely at random) I get a datetime overflow when inserting or updating a record that contains one or more datetime fields. (SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999)
When checking the object that's saved by OpenAccess, all present datetime fields are filled and in range. There should be absolutely no reason why it gives me an overflow exception. When I reset and try to insert/update the same records, sometimes it works.
This behaviour seems to happen more often when using the GetContextPerRequest method found in the best practices but also when always initiating a new instance.

Any ideas?

Erik

2 Answers, 1 is accepted

Sort by
0
IT-Als
Top achievements
Rank 1
answered on 14 Dec 2011, 01:37 PM
Hi Erik,

I don't know if this has something to do with GetContextPerThread method... maybe, maybe not..  holding for the latter though.
The exception you get is because the value is out of range of the SqlDateTime range... typically this is because of the DateTime (.NET) property not being filled (thus it is null)  If you want to allow null values, please make it nullable, either with ? or Nullable<DateTime>.

Double check your code to see if this property get its values at all possible paths through your code.

As this is an exception on insert and update it makes no sense to look in the database to check if the DateTime column are filled in... because the object never goes to the DB.

Hope to help - or at least give you some hints in the right direction.

/Henrik
0
Ady
Telerik team
answered on 19 Dec 2011, 12:52 PM
Hello Erik,

@Henkrik - Thank you once again for the valuable input.

@Enrik - Henkrik has provided useful hints in his answer. The exception should not have anything to do with the 'GetContextPerRequest' method. Have you turned on logging so that you can see what SQL and parameter values are used by OpenAccess? This should give you the exact query and values that are being inserted. You can find more information about logging, here.
Can you provide the entire exception stack trace,ifpossible. This information could help to get a better insight.

Best wishes,
Ady
the Telerik team

Q3’11 of Telerik OpenAccess ORM is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

Tags
General Discussions
Asked by
Erik
Top achievements
Rank 1
Answers by
IT-Als
Top achievements
Rank 1
Ady
Telerik team
Share this question
or