[Solved] Entity Framework Core Asp.Net Core 3.1 Error: SqlException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. The statement has been terminated


Question: How do you resolve the error: SqlException: The conversion of a datetime2 data type to a DateTime data type resulted in an out-of-range value. The statement has been terminated

 


Login to See the Rest of the Answer

Answer:
Take a look in your Database table, chances are that you have created a DateTime column in your Database table and made it nullable at the same time, you added a default-binding of getdate() to populate the column with default date.

However in your application code, you are not defining what that DateTime should be in the Database Table column, since you made the DateTime nullable in the database, it is expecting the DateTime to be populated by application code. You should explicitly pass in the DateTime in your data modal class or make the column field not nullable in your database table while you allow default-binding of getdate().

 

Call to Action: Sign up for a free account so to be notified when a new solution is found.





Jim said:

SqlException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. The statement has been terminated. My answer is: The date passed into the Controller is most likely null or is set to default. Make sure you set the date in your Controller when the payload has been received.

Posted On: March 24, 2022 16:37:08 PM
Josh said:

If you still have an error, make sure you create a handling object e.g. MyPocal pocal = _callYourService.Function this way you the result from the _callYourService.Function is kept in pocal object. This is the work around this problem.

Posted On: February 18, 2022 21:15:38 PM

For peering opportunity Autonomouse System Number: AS401345 Custom Software Development at ErnesTech Email AddressContact: [email protected]