An error occurred while executing the command definition. See the inner exception for details. bbbbInnerException:aaaa System.ArgumentException: The version of SQL Server in use does not support datatype 'datetime2'.
at System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavioR
I have a website using Entity Framework. A few months ago I added a new table, and added some columns to existing tables; everything worked fine.
Today I updated the mapping of the EDMX so the new table and the new column can be used, and added WebMethods to my services.asmx file. Since then I cannot run my site because I have that error that I cannot understand. Please explain it to me if you understand, and tell me where is my mistake.
I have not used datetime2 anywhere. There is no such datatype in my new table, nor in the columns that I added to existing tables.
The version of SQL on my PC is SQL2008 R2, on the server i have SQL2008. I do not have the option to upgrade the server to R2.
Open your EDMX in a file editor (or “open with…” in Visual Studio and select XML Editor). At the top you will find the storage model and it has an attribute ProviderManifestToken. This has should have the value 2008. Change that to 2005, recompile and everything works.
NOTE: You'll have to do this every time you update the model from database.
The other solutions worked for me but I needed a more permanent solution that would not be reverted every time the edmx was updated from the database. So I created a "Pre-build event" to modify the ProviderManifestToken automatically.
Link to original answer: https://stackoverflow.com/a/8764394/810850
The prebuild step looks like this:
The code is here:
Have you tried to open your EDMX file with XML Editor and check the value of
ProviderManifestToken
. It may help to change fromProviderManifestToken=”2008”
toProviderManifestToken=”2005”
.Code First workaround.
I got this error while running a linq select query, and changing the EDMX isn't an option for me (Code First has no EDMX), and I didn't want to implement this How to configure ProviderManifestToken for EF Code First for a Linqpad query that wasn't going into production code:
I fixed it by changing
query
to null check first:In addition to @Mithrandir answer validate that your database is running in compatibility level set to 100 (SQL 2008).
You don't have to use
DATETIME2
in your database to get this error. This error happens usually once you add required (NOT NULL
)DATETIME
column to existing table and you don't set the value prior to saving the entity to database. In such case .NET will send default value which is 1.1.0001 and this value doesn't fit intoDATETIME
range. This (or something similar) will be source of your problem.