Bug #53254 MySqlDateTime - GetDateTime - throws exception
Submitted: 28 Apr 2010 15:05 Modified: 29 Apr 2010 17:28
Reporter: blabla ballalsj Email Updates:
Status: Closed Impact on me:
Category:Connector / NET Severity:S1 (Critical)
Version:6.3.1 OS:Windows (7)
Assigned to: CPU Architecture:Any

[28 Apr 2010 15:05] blabla ballalsj
When using the 6.3.1 connector, if the column in the database is DateTime and the value in that field is 0000-00-00 for example, then an error is thrown : 

MySqlConversionException("Unable to convert MySQL date/time value to System.DateTime");

How to repeat:
Create a table with a DateTime column, set the value in it to '0000-00-00'. Map the table with Entity Framework 4 . Try to execute a select from that table.

Suggested fix:
The fix would be to return DateTime.Min like the explicit operator DateTime implementation.
[29 Apr 2010 5:29] Tonci Grgin
Hi Sirrocco and thanks for your report.

Please *please* do not use me to read manual instead of you...
So, do take a look into http://dev.mysql.com/doc/refman/5.1/en/connector-net-connection-options.html and correct the values of "Allow Zero Datetime" and "Convert Zero Datetime" to suite your needs.

System.DateTime cannot represent zero datetime values. MySqlDateTime does support zero datetime values (for legacy reasons).

Allow Zero Datetime = False
- Zero datetime values are not allowed.
- Exception is thrown for illegal values (presumably that includes zero datetime values).

Allow Zero Datetime = True
- MySqlReader.GetValue() returns a MySqlDateTime for illegal values.

The intention is to return a DateTime in every case that the value is legal and MySqlDateTime in other cases.
[29 Apr 2010 17:28] blabla ballalsj
Hi Tonci

I'm very sorry for this, I did search for a solution to the problem and I had only found "Allow Zero Datetime" and that didn't work.

I tried "Convert Zero Datetime" and it did the trick.

Again, I'm very sorry for wasting your time.