maandag 23 augustus 2010

Entity Framework: ‘does not support datatype datetime2’

While testing on my local development machine, I use a SQL Server 2008 instance. I generated the EF model using that same local database and everything works fine. After the testing period, I wanted to run the same tests on a production server.
The moment I tried to update an entity containing a datetime field, I received the following exception message:

“The version of SQL Server in use does not support datatype 'datetime2'.”

image

After checking the ddl of the tables on both test and production database, I found no differences.
What was the problem (and solution)?

It turns out that the model generator puts some database targeting information in the generated model (the edmx file). Since my production database was still a SQL Server 2005 instance, using the model on that database gives runtime errors, because statements are generated that the SQL Server database doesn’t understand. The problem is here (in the edmx file):

image

The ‘ProviderManifestToken’ attribute indicates that a SQL Server 2008 database was targeted. When you change this to ‘2005’ everything works fine again (even when you are connecting to the SQL Server 2008 database).

Geen opmerkingen:

Een reactie posten