Unable to convert MySQL date and time value in System.DateTime in VS2010

when I want to load data from my mysql database, I always get this error:

Cannot convert MySQL datetime value to System.DateTime

This is my connection string:

<add name="gdmwebsiteEntities" connectionString="metadata=res://*/Models.DBModel.csdl|res://*/Models.DBModel.ssdl|res://*/Models.DBModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=localhost;User Id=root;database=gdmwebsite&quot;" providerName="System.Data.EntityClient" /> 

I already added "Convert Zero Datetime = True" to add the end of my connection string, but nothing has changed.

  <add name="gdmwebsiteEntities" connectionString="metadata=res://*/Models.DBModel.csdl|res://*/Models.DBModel.ssdl|res://*/Models.DBModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=localhost;User Id=root;database=gdmwebsite&quot; Convert Zero Datetime=True Allow Zero Datetime=True" providerName="System.Data.EntityClient" /> 

Is there any other way to do this?

+7
source share
1 answer

Define both of these configurations in the connection string.

 "Convert Zero Datetime=True" "Allow Zero Datetime=True" 

http://bugs.mysql.com/bug.php?id=26054

Please check the connection settings guide and set "Allow zero" Datetime "to true, as in the attached images, and the error will go away.

Check this out as well: http://mdid.org/mdidwiki/index.php?title=Unable_to_convert_MySQL_date/time_value_to_System.DateTime_exception

To resolve this issue, either replace all invalid timestamps with NULL or a valid timestamp, or add Allow Zero Datetime = true

+20
source

All Articles