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

Problem

You receive the following message when running your application:

Unable to get records. Unable to convert MySQL data/time value to System.DateTime.

In certain versions of MySQL, date values are saved as 0000-00-00 instead of a NULL which causes an error when running your application.

Problem

Step 1: Make sure that date columns in the MySQL database either contains all valid values or contain NULL.

Step 2:  Add the “Allow Zero Datetime=true” attribute to your database connection string in your application’s Web.config file, e.g.:

<add name="Databasesalika1"

     connectionString="Data Source=qaxp-net;Port=3306;

     Database=salika;

     User Id=ironspeed1;Password=ironspeed1;

     Allow Zero Datetime=true"

     providerName="MySql.Data.MySqlClient"

/>

For additional information on this topic:

http://mdid.org/mdidwiki/index.php?title=Unable_to_convert_MySQL_date/time_value_to_System.DateTime_exception

See Also

Part VII:  Troubleshooting Applications

Application Will Not Run

Application Runs But No Data is Displayed

Application Error Messages