SuppressGetDecimalInvalidCastException
This property specifies whether to suppress the InvalidCastException
and return a rounded-off 28 or 29 precision Oracle NUMBER
value that can be represented as a .NET Decimal.
Declaration
// C# public static bool SuppressGetDecimalInvalidCastException {get; set;}
Property Type
System.Boolean
Remarks
Oracle NUMBER
has a maximum of 38 precision. .NET Decimal has a maximum of 28 or 29 precision. When the OracleDataReader GetDecimal()
, GetValue()
, or OracleDataAdapter Fill()
method is called for an Oracle NUMBER
value that cannot be represented as a .NET Decimal, then ODP.NET throws an InvalidCastException
because not all the precision can be preserved when converting the number to a .NET Decimal.
This behavior occurs when SuppressGetDecimalInvalidCastException
is set to false
, which is the default value.
When SuppressGetDecimalInvalidCastException
is set to true
, the resulting .NET Decimal is rounded off to 28 or 29 precision, allowing as much of the value to be represented without throwing an exception. If the resulting rounded number is larger than can be stored in a .NET Decimal, then an exception will be thrown, such as the number 1 x 10^32.
By using OracleConfiguration.SuppressGetDecimalInvalidCastException
, this ODP.NET setting becomes enabled globally for the app. It can be overridden at the OracleConnection
, OracleDataReader
, or OracleDataAdapter
level, which each has its own SuppressGetDecimalInvalidCastException
property.
See Also:
-
OracleConnection SuppressGetDecimalInvalidCastException
-
OracleDataReader SuppressGetDecimalInvalidCastException
-
OracleDataAdapter SuppressGetDecimalInvalidCastException
-
"Oracle.DataAccess.Client and Oracle.ManagedDataAccess.Client Namespaces"