Entity Framework Error – The version of SQL Server in use does not support datatype ‘datetime2’

I am using Entity Framework 4.0 in an ASP.NET 4.0 Web Form.

All is fine on the development server. But when I get to the production server, I my Elmah logs this error

System.ArgumentException
The version of SQL Server in use does not support
datatype ‘datetime2’.

I did a quick research and found out that datetime2 aka datetime2(7) is the problem and setting ProviderManifestToken="2005" will solve the issue.

My problem is this. My Development Server has SQL Server 2008 R2 and Production Server has SQL Server 2008 Express. So, changing the manifest to 2005 doesn’t seem right.

My questions are

  1. Will setting ProviderManifestToken="2005" work?
  2. Why has Entity Framework generated a datetime2 when I haven’t used it at all in any of the table?
  3. Is there a better work around?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I dont see any workaround till date. So if you are using SQL Server 2008 Express, please right click on your edmx, open it with XML (Text) Editor and set ProviderManifestToken="2005".

Doesn’t sound that good. But its all I have got as of now.

Method 2

I found that the answer in this blog post worked for me: The version of SQL Server in use does not support datatype ‘datetime2’

It turns out that Entity Framework 4 somehow got the idea to use SQL Server 2008. The fix was to edit the .edmx file in an XML editor and set the ProviderManifestToken=”2005″ instead of 2008. (You need to rebuild.) Here’s how the line should look against SQL Server 2005:

<Schema Namespace="OfficeBookDBModel.Store"
    Alias="Self" Provider="System.Data.SqlClient"
    ProviderManifestToken="2005"
    xmlns:store=http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator
    xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">

Method 3

Just put DateTime.Now as the date if you have no other…

Had the same error and this solved it because if you dont set a value for your date time object it will be 1/1/0001 12:00:00 AM…this give you the error then… again this is how i solved the problem


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x