I am wondering if this is a mistake or if something is wrong.
I load values using SqlDataReader from a SQL Server 2008 database, but under certain circumstances it cannot convert SQL values to .net values. (.NET 4.0)
I traced it to a test case that shows the actual problem:
Working example:
"select convert(decimal(38, 19), 260000 ) as test" rs.GetValue(1); --> returns 260000 (decimal)
Exmaple does not work:
"select convert(decimal(36, 26), 260000 ) as test" rs.GetValue(1); --> throws System.OverflowException: Conversion overflows. at System.Data.SqlClient.SqlBuffer.get_Decimal() at System.Data.SqlClient.SqlBuffer.get_Value() at System.Data.SqlClient.SqlDataReader.GetValueInternal(Int32 i) at System.Data.SqlClient.SqlDataReader.GetValues(Object[] values)
I reviewed the actual values that SQL Server saved. They differ in that the non-worker uses 4 integers to express the value, and the worker uses only 3.
I also checked the source code with .net Reflector, which imagined that an exception is thrown if the value exists for more than 3 values, but I don’t understand what the mechanics are behind.
So, I am wondering if this is a genuine bug in the .NET Framework.
Chuck
source share