0

Is there any way to determine which column is causing the problem? Yes, I can manually look through the objects I'm trying to insert/update and check all the properties but I'm looking for a more robust solution. For example, SQL Server now returns the truncated column. Is there an equivalent for datetime's?

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.

Yes, I'm sure I have a System.DateTime this is System.DateTime.Minimum and the column in SQL Server is defined as datetime. I'm aware of the fix .

spottedmahn
  • 11,379
  • 7
  • 75
  • 144
  • This isn't as simple as the truncated data issue. The conversion could be in the data, it could be in join predicates, it could be where predicates. – Sean Lange Sep 11 '19 at 18:59
  • In SSMS, you can select the columns in question with TRY_CONVERT() and test for a null return, which should enable you to find exactly which rows have values in that column that won't convert correctly to datetime. – pmbAustin Sep 11 '19 at 19:18
  • Look for dates before 1753 (without attempting to do the conversion.) Can you narrow it to a single expression or column? – shawnt00 Sep 11 '19 at 19:56

1 Answers1

0

The reason for this SqlException is that the minimum date returned by System.DateTime.Minimum is 01/01/0001 while SQL Server only supports datetimes starting from 01/01/1753.

If I'm not mistaking, you could use SqlDataTime.MinValue in .NET which should solve your issue.

Kevin
  • 751
  • 5
  • 11