SqlDatetime overflow  
Author Message
Omar#





PostPosted: .NET Framework Data Access and Storage, SqlDatetime overflow Top

Hi guys

the error SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. has me crazy!

Is become from sql server, framework, regional setting on client pc or what

I trying to input a begin date 01/06/2006 (default language of the database is m/d/y), the application (asp page) begin date when load the module is 01/01/1. In a environment producction the database is formating equals like the enviroment test and no problems whith dates formats.

Any ideas

Thanks,



.NET Development19  
 
 
kbradl1





PostPosted: .NET Framework Data Access and Storage, SqlDatetime overflow Top


You can't insert the DateTime.MinValue into SQL. Somewhere you have a bug where a DateTime variable has not been assigned a value.

 
 
VMazur





PostPosted: .NET Framework Data Access and Storage, SqlDatetime overflow Top

Most likely you concatenatig the date value to your query string and this causes the issue. Depending on a regional settings on your PC format of the dates could be different and provider starts to complain. To resolve the issue you need to use parameterized queries and pass date as a parameter.

 
 
Omar#





PostPosted: .NET Framework Data Access and Storage, SqlDatetime overflow Top

Vmazur,

i only must configured the regional settings in the client pC Basically i have a web page to input a begin date/end date, any date that begin with 01,02,03(dd/mm/yyyy) p.e. 01/06/2006 become an the error above, Otherwise if the date is like this (10/06/2006 and 27/06/2006) the application is no has any mistake.

the language setting in the sql is (m/d/y), the language in my country is (dd/mm/yyyy). In the environment producction the sql language is (m/d/y) and the application is working very well inputing the date in the format (dd/mm/yyyy). The sql language int the environment test is confured like the production environment.

Environment Production:

Win 2003 server Sp1, Sql 2000 Standard Edition SP4, framework 1.1, IIS 6.0

Environment Test:

Win Xp SP2, Sql 2000 Personal Edition SP2, Framework 1.1, IIS 5.1

I hope this information help you to understand my problems with the SqlDatetime overflow.

Thanks for all!


 
 
VMazur





PostPosted: .NET Framework Data Access and Storage, SqlDatetime overflow Top

In a case of the Web pages, your application will use date format of the Web server where application running, not from the client. Check what you have on a server side. If your date format on a server set to mm/dd/yyyy, you could get an error.

 
 
dmls





PostPosted: .NET Framework Data Access and Storage, SqlDatetime overflow Top

how are you binding from .net to sql server

sounds like an implicit rather than explicit type conversion,

convert your date string to a date variable type and ensure that the variable type that you are binding to the database is a date/datetime type

then you should not have to worry about your region settings on your machines because the framework and the database will (internally) use non regionalised forms of the date (i think it actually stores a date as a numeric value)


 
 
Peter0007





PostPosted: .NET Framework Data Access and Storage, SqlDatetime overflow Top

Using "Date.Now.ToShortTimeString" as the value to be passed as a parameter will generate the same error message, but if you use "DateTime.Now.ToLocalTime" everything should work just fine.


 
 
Mona Mahran





PostPosted: .NET Framework Data Access and Storage, SqlDatetime overflow Top

I got the same error it is because you are trying to update a datetime field which is having a default value so you will have to let it allow null in the database and don't give it a default value and update it in the code with the value you want.

Best Regards,

Mona Mahran