Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003
    Location
    Peabody, MA
    Posts
    919

    MySQL Zero Datetime Related Issue

    So I got the MySQL ADO.NET adapter installed and then using the Entity framework, generated a bunch of model classes. I was getting this error when selecting data from a certain table:

    Unable to convert MySQL date/time value to System.DateTime

    So after researching that real quick, I added this to my web.config for my mysql connection string:

    Allow Zero Datetime=True;

    However I am now getting the following error:

    Object reference not set to an instance of an object.

    This has something to do with one of my fields in my database holding '0000-00-00 00:00:00' as the value because if I set that to some other valid timestamp it works fine however this field is often going to hold zero data as it is only updated if the record is updated. I have also tried allowing NULL for the field and setting it to null but the same error comes up. Does anyone know how to fix this issue?
    Ryan Zec

    My Blog: http://www.underthecode.com

  2. #2
    Join Date
    Jun 2005
    Location
    Phoenix, Arizona
    Posts
    2,076
    Edit: I found this in a google search so see if this will work for you otherwise I would suggest what I said below. http://social.msdn.microsoft.com/For...-55e801d96cf3/

    Well I have never used MySQL with the Entity Framework but typically if I have a datetime that I don't want to allow null in but want a default date I will just use something like "1901-01-01 00:00:00". It's most likely having an issue with the fact that the date is all zeros. I know Microsoft SQL Server can't handle a date like that so if you just give it a valid date that is not below the minimum threshold in MySQL you should be good.
    Last edited by Grinch78; 12-06-2010 at 09:30 AM.

  3. #3
    Join Date
    Aug 2003
    Location
    Peabody, MA
    Posts
    919
    Yea, actually updating the database to allow the value NULL and have that as the default worked. I though it didn't work at first but apparently the visual entity design is still buggy. Once I completely deleted the entity generated file and re-created from scratch, the newly generated code worked.

    I am now investigating using POCO with the entity framework as I really don't want to deal with the visual design (especially if it is buggy).
    Ryan Zec

    My Blog: http://www.underthecode.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •