Dienstag, 27. Juli 2010

SQL Server 2008 datetime2 issue

If you got the following error in an INSERT statment from entity framework to MSSQL 2008: System.Data.SqlClient.SqlException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.

Solution:
The problem occurrs when you use Entity Framework to INSERT a System.DateTime (a not initialized one like 0001-01-01 00:00:00.0000000) into the SQL2008 DB. Change the datatype in DB to datetime2 and everything will run smoothly.
Another solution is to initialize the datetime field with a value greater than 1/1/1753.

Keine Kommentare:

Kommentar veröffentlichen