I've built a entity framework model against a 2008 database. All works ok against the 2008 database. When I try to update the entity on a 2005 database I get this error.
The version of SQL Server in use does not support datatype 'datetime2
I specifically did not use any 2008 features when I built the database. I can't find any reference to datetime2 in the code. And, yes the column is defined as "datetime" in the database.
This is very frustrating and I am surprised MS decided not to make it so you could target a given SQL version. To make sure we are targeting 2005 I wrote a simple console app and call it in a PreBuild step.
The prebuild step looks like this:
The code is here:
For the benefit of people who encounter the same issue but are using Code First, check out my answer here about how to change the
ProviderManifestToken
in Code First. It involves creating aDbModelBuilder
manually and passing aDbProviderInfo
instance (with the appropriate token) when calling the model builder'sBuild
method.We had this error on SQL2005 v.3, where we did not have it on SQL2005 v.4.
Adding SQL2005 to the connection string fixed our specific problem.
We haven't identified why yet, and did not want to modify code to provide the token as solved above (issue manifested during deployment).
Quick view of line:
Had a similar problem with 2012 vs. 2008. It can be solved with a BeforeBuild event using XmlPeek and XmlPoke:
If you dislike automated replacement, you can simply replace the XmlPoke task with an Error task.
Using @Vance's handy console app above, I used the following as a BeforeBuild event
This is super handy, as avoids annoying redeployment. Thanks for sharing Vance.
I've added TF.exe to the Library solution folder and this helps, as I can now check out the edmx files before trying to edit them, as part of the build. Also I have added this with conditions, so that it sets to 2005 for deployments to the server and back to 2008 for the Dev machine sln configurations. Also to mention you need to add the actual SetEdmxSqlVersion.exe (and .pdb) file(s) to the Library folder (or wherever else you want to keep these bits).
Thanks very much @Vance. Really neat, massive time saver and keeps my builds totally automated and pain free :)