Question

I have a basic error:

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.\r\nThe statement has been terminated.

I have this thing in multiple places, but when stack trace throws an exception I don't know how to find what method or part of code is causing the problem.

The problem is its hard to debug, because when I add 1 element it works properly, when I loop I guess It loses the assignment of datetime somehow.

The code is too long, I just need a tip how to read the stack trace when it throws the exception.

enter image description here

Was it helpful?

Solution

The stack trace might not display all you want, however, try peeking at tab on the right: might be the select statements (probably the very last one) are causing the error, you might wanna check them out.

Also, I would recommend use appropriate types for your tables in your SQL database, such an error indicates an error in the architecture, you might want to reconsider (or at least, check out each row for its type) your database types for the data the might carry.

OTHER TIPS

Look at the callstack window. I extracted this from your screenshot:

Callstack window

This is not where the exception is thrown, but this is where you can handle it. Your code calls someone else's method and you probably passed an argument which is invalid.

The exception is thrown in external code, which means not your code. However, unless you assume it's a bug in someone else's code (e.g. Microsoft) and you want to submit a bug report to Microsoft, you don't need that information.

If you really want to know where the problem occurs, right click the callstack and enable [x] Show external code. Be aware that you might not have the source code and even never get it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top