Hello
When i save with dbContextSave(), i get an error on SqlTypeException
Can i get a Handling SqlTtype Exception when i Save my data ?
in try catch ?
Cause i want to find the name of column, which not set a good value.
And the error is not explicit . i Get ????????????
So i want to write in Log output to see that
thanks
System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
7 Answers, 1 is accepted
On the first look, I can see that some DateTime property throws exception. That often happens when some posted property is not initialized or has date before 1/1/1753. My recommendation in this case, is to review all of your properties from DateTime type and see is there any properties with not correct data.
After that you can try with log statements (generated by the OpenAccessContext). Please take a look at this article that actually illustrates how to enable tracing and logging.
Pavel Uzunov
Telerik
Hello
Have you a sample to browse each properties which are in DateTime ?
to show the name and the value ?
thanks
Olivier
You can use our change tracking API (as shown here: How to get changes that will be performed during the next commit. ) to list all changed objects right before calling the context.SaveChanges() method and then inspect each of the properties. You could do it manually during debugging or write some reflection code that would do it automatically.
I hope this helps
Regards,
Pavel Uzunov
Telerik
I have encountered this exception before using nhibernate (I was careful not to do it again in Data Access).
I am pretty sure this is the result of not initializing a non-nullable DateTime field then saving. The default value for a DateTime is not in the range valid SqlTimes.
Using LinqPad:
var d =
new DateTime()
;
d.Dump();
// "1/1/0001 12:00:00 AM"
You need to either initialize the date to a valid value or make it nullable. What you do depends on if the field is nullable in the database.
Your are right, in most of the cases this is the case for such issues.
Regards,
Pavel Uzunov
Telerik
I came across my error, testing all date fields, and fields had the date of 01/01/0001 therefore not Gregorian.
But it would be simpler, that the save, (I know that launches a procedure stored after)
we can say is the date_update fields.
If this is not possible, I have found a book that makes me gain more time.
Thank you
You can use our change tracking API to detect the objects to be inserted and using reflection to set the DateTime properties to the desired value, right before calling the context.SaveChanges() method. You can take a look at this article.
Another solution is to make nullable your DateTime properties (in case this is not an issue for your data model). This will instruct DataAccess to not include them in the insert statements.
I hope this helps.
Regards,
Pavel Uzunov
Telerik