I'm getting an exception report from a vb.net Windows Forms app I made via the exception reporting system I built into it. Some users are getting an exception with message "Value was either too large or too small for a Decimal.Couldn't store <8> in PrdHrs Column. Expected type is Decimal."
The stack trace included tells me the method, and that message narrows down where the exception is being hit, but I can't figure out what "<8>" means. Does that just mean the value of 8, but it's displayed with less than/greater than symbols around it? Or does that imply a certain value type? Google is basically impossible to search for this.
I suspect that that '8' actually is an infinity symbol but it's not displayed properly in whatever you're seeing. I just tried this code:
Dim dbl = Double.PositiveInfinity
Dim table As New DataTable
table.Columns.Add("Number", GetType(Decimal))
table.Rows.Add(dbl)
and this was the message I got:
System.ArgumentException HResult=0x80070057 Message=Value was either too large or too small for a Decimal.Couldn't store <∞> in
Number Column. Expected type is Decimal. Source=System.Data
StackTrace: at System.Data.DataColumn.set_Item(Int32 record, Object
value) at System.Data.DataTable.NewRecordFromArray(Object[] value)
at System.Data.DataRowCollection.Add(Object[] values) at
ConsoleApp1.Module1.Main() in C:\Users\johnm\AppData\Local\Temporary
Projects\ConsoleApp1\Module1.vb:line 12
Inner Exception 1: OverflowException: Value was either too large or
too small for a Decimal.
It's not ideal that you are working with Double values and then storing the results as Decimal values. It may be unavoidable but, if so, you need to do a bit better at validation. You are probably dividing by zero, which is legal for Double values and produces either Double.PositiveInfinity or Double.NegativeInfinity.
Related
I have a rudimentary application which uses a System.Data.Odbc.OdbcDataReader and the Read method to step through individual rows returned by a query sent to a Redshift database.
I want to get a rough estimate of the size of the row as it relates to the amount of data physically sent over the network. With this information, I could calculate that TotalRows * RowSizeInBytes = DataTransferSize.
My thought was to retrieve the type of each column returned with GetType() then use System.Runtime.InteropServices.Marshal.SizeOf() to get the actual size of the data and add it all together.
I have found that I could not call the SizeOf method on a String or on a DateTime. I get an error similar to the following:
System.ArgumentException: 'Type 'System.DateTime' cannot be marshaled as an unmanaged structure; no meaningful size or offset can be computed.'
I started to create an if block that would recognize a String type and use the Length() method on the String rather than the marshal method. But, this led me to wonder if this is the correct way to do this.
My code looks like this:
reader.Read()
For a = 0 To reader.FieldCount - 1
Console.WriteLine(reader(a).GetType().ToString() + ": " + reader(a).ToString())
If reader(a).GetType() = GetType(String) Then
Console.WriteLine(reader(a).ToString().Length)
Else
Console.WriteLine(System.Runtime.InteropServices.Marshal.SizeOf(reader(a).GetType()).ToString())
End If
Next
Can someone provide guidance on the correct way to get the approximate size of the row, in bytes, sent over the wire? My gut tells me that data type mismatches between the underlying database, the operating system/driver, and the programming language makes the size of particular data types (sent over the wire), such as integers, somewhat ambiguous. I am less worried about this, but I would like a solution to consider this.
I have a user defined CLR aggregate function that can potentially throw an error. I would like to know how to handle an error if one occurs in my query.
The function is performing an IRR calculation similar to that which Excel does, ie. an iterative root-finding calculation. If no root is found, an error is thrown. This is the error I need to handle.
The query is part of a larger stored procedure and it looks something like:
select
MyID,
Excel_XIRR(col1)
from #t
group by MyID
and the error i get is something like this:
A .NET Framework error occurred during execution of user-defined routine or aggregate "Excel_Xirr":
System.ArgumentException: Not found an interval comprising the root after 60 tries, last tried was (-172638549748481000000000.000000, 280537643341281000000000.000000)
System.ArgumentException:
at System.Numeric.Common.rfindBounds#59(FastFunc`2 f, Double minBound, Double maxBound, Double precision, Double low, Double up, Int32 tries)
at System.Numeric.Common.findBounds(FastFunc`2 f, Double guess, Double minBound, Double maxBound, Double precision)
at System.Numeric.Common.findRoot(FastFunc`2 f, Double guess)
at Excel_Xirr.Terminate()
My problem is that not all the rows cause this error. There are some legitimate results from the query that I want to capture and use later in my stored procedure. Will this error stop me from getting the results of the query? If so, is there a way to figure out which rows throw the error (dynamically) and then rerun the query for the rest of the rows?
Not sure how well you have coded the XIRR function itself, looking at your function prototypes in Error messages it would seem you are using a Bi-section method of finding roots which is not most suitable to algorithms to use when it comes to finding rates. You will be locking yourself within a lower and upper bound no matter how large this bound is it is not going to help for all cases
As for solving your immediate problem with handling the error, you can change your .net code and replace the Throw...Exception statement with a return value of Math.Pow(-1, 0.5)
This will return a NAN to the calling program which you can then check with an IF statement to confirm whether your XIRR value is a number (when IRR is found) or a NAN value (when IRR is not found)
Does anyone know the consequence of not setting all fields value on a OracleParameter in order to execute a storedprocedure?
For instance, is it necessary to provide OracleDbTypeEx, Size?
I would simply provide name, value, inOrOut?
What do you think?
Thank you.
For input parameters, type is infered from the value if it's not specified. That said for code neatness and maintainability I tend to NOT set these properties for inputs, using the Parameters.Add method in a similar method to the AddWithValue method found on the SqlCommand class: cmd.Parameters.Add("myvarname", varvalue).
Length on the other hand does change the behavior. IIRC, if you do not specify length, a form of overflow exception is raised when the value length exceeds the parameter length. If you do set length, the input is trimmed to that length, at least in the case of String/Varchar. I tend to stay away from setting length since I would perfer to be alerted of truncation and would instead limit input on the front end.
Output parameters are a different story. Not setting output variable type and length tends to result in "character string buffer too small" and "illegal variable name/number," so in most cases you do need to set these properties for output parameters.
I've got a typed dataset. I bind the data with a binding source to a form with arround 200 textboxes, dataedits and so on. Everything works fine with one exception:
In my database I have empty DateTimes (DBNull.Value). And when they get bound to a DateEdit-Control, I get the following exceptions:
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.Data.StrongTypingException' occurred in myTestDLL.dll
I tried to change the NullValue-Property in the DataSet-Desinger to something else as 'Throw Exception', but it doesn't work for a DateTime. For other types like Integer or String it works fine.
I dont know a nice solution (right now I fill the empty dates with some dummy date and make it invisible in the DateEdit-Control, but this is very uncool) and I hope to find some help here.
It seems that many people got the same problem but I didn't find a solution :(
Why not just skip if test fail ?
if dMyDate is dbnull.value then 'skip, msgbox, set to date.minValue, whatever
When i send:
Result = CInt(NetApiBufferFree(pBuffer))
I receive (SOME TIMES) this error:
Arithmetic operation resulted in an overflow.
What exactly means that? and how i can resolve it?
It means that CInt argument is out of range of Integer, -0x80000000 to 0x7FFFFFFF
And it happens when NetApiBufferFree returns an error: error codes are bigger than 0x80000000.
There is no unsigned int32 type, so use CLng instead of CInt.
About source of error. You should find out code of error which you get: call MsgBox or log it to file, or use breakpoint. Next find its description. If it won't help you (for example error would be E_FAIL), add code to check that pBuffer value is valid - that it wasn't modified by something, and wasn't already freed. Add logging for NetApiBuffer* calls.
Best answer is replace 'double' in place of 'Int16/Int32/Int64'
some times file conversion takes huge numbers.. double never has maximum range.