DateTime overflow exception

3 posts, 0 answers
  1. Erik
    Erik avatar
    3 posts
    Member since:
    Nov 2011

    Posted 14 Dec 2011 Link to this post

    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. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 14 Dec 2011 Link to this post

    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
  3. DevCraft banner
  4. Ady
    Admin
    Ady avatar
    589 posts

    Posted 19 Dec 2011 Link to this post

    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!

Back to Top