Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

SqlDateTime overflow Expand / Collapse
Author
Message
Posted Wednesday, January 9, 2013 12:56 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, April 18, 2014 12:58 PM
Points: 367, Visits: 614
I use .NET 4.0 and they did not update the date range limits in the libraries to match the new range in SQL Sever. I will have to wait until I get home, but will try to find a workaround I came up with and post it here for you.

This was a one week research project for me so if I can find my fix it could save you a ton of time.
Post #1404960
Posted Wednesday, January 9, 2013 2:47 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, July 12, 2013 7:25 AM
Points: 39, Visits: 144
Thanks so very much. It would look like MS would fix this.
I set my dates fields to "date" in sql and my time to "time(4)
Post #1405026
Posted Wednesday, January 9, 2013 3:00 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, April 18, 2014 12:58 PM
Points: 367, Visits: 614
Different dev teams I guess. Not very efficient.
Post #1405034
Posted Wednesday, January 9, 2013 8:13 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, April 18, 2014 12:58 PM
Points: 367, Visits: 614
OK, just so everyone understands, this is not a SQL problem. The .NET Framework has a special data type for SQL databases in System.Data.SqlTypes.SqlDateTime. For some really silly reason, this data type's MinValue method has not been expanded to use the new minimum date. Probably because no one at Microsoft even thought about adding a SqlDateTime2 type, or any of the others like SqlDate and SqlTime.

What I had to do is find the code in my data access library that used SqlDateTime.MinValue to check dates before sending them to the database and changed it to use DateTime.MinValue. That will use the proper minimum date.

Do be sure and use DateTime2 in SQL or the database will be the next thing that will throw an error.

Hope this helps.
Post #1405138
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse