Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The version of SQL Server in use does not support datatype datetime2?

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.

like image 576
Barbara88 Avatar asked Apr 19 '12 08:04

Barbara88


People also ask

What is DATETIME2 data type in SQL Server?

Defines a date that is combined with a time of day that is based on 24-hour clock. datetime2 can be considered as an extension of the existing datetime type that has a larger date range, a larger default fractional precision, and optional user-specified precision.

What is a DATETIME2 data type?

SQL DateTimeOffset. The DATETIME2 data type specifies a date and time with fractional seconds. DATETIME2 supports dates from 0001-01-01 through 9999-12-31. The default value is 1900-01-01 00:00:00. The time is based on a 24-hour clock.

How insert DATETIME2 value in SQL Server?

Always use the format YYYY-MM-DD hh:mm:ss[. nnnnnnn] to insert the date into database. This is the default format that SQL Server uses. It is also the safe format and can be interpreted only in one way.

Should I use DATETIME2 or Datetimeoffset?

If you are storing only UTC values (where the offset is always zero), you can save storage space with datetime2 . datetimeoffset requires 10 bytes of storage whereas datetime needs 8 bytes for precision 5 or greater, 7 bytes for precision 3-4, and 6 bytes for precision 2 or less.


3 Answers

Have you tried to open your EDMX file with XML Editor and check the value of ProviderManifestToken. It may help to change from ProviderManifestToken=”2008” to ProviderManifestToken=”2005”.

like image 179
Mithrandir Avatar answered Oct 07 '22 20:10

Mithrandir


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 into DATETIME range. This (or something similar) will be source of your problem.

like image 23
Ladislav Mrnka Avatar answered Oct 07 '22 18:10

Ladislav Mrnka


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.

like image 31
Maher Ben Issa Avatar answered Oct 07 '22 18:10

Maher Ben Issa