You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am encountering a System.OverflowException when executing the System.Data.Odbc.OdbcDataReader.GetSqlType(int i) method in my code. The error occurs specifically when the result of the GetColAttribute method is a negative integer, which happens with the 64-bit ODBC driver used to access an HFSql database (PC Soft).
Here is the exception I am encountering:
Arithmetic operation resulted in an overflow.
System.OverflowException: Arithmetic operation resulted in an overflow.
at System.IntPtr.ToInt32()
at System.Data.Odbc.SQLLEN.op_Implicit(SQLLEN value)
at System.Data.Odbc.OdbcDataReader.GetSqlType(Int32 i)
at System.Data.Odbc.OdbcDataReader.GetValue(Int32 i)
at System.Data.Odbc.OdbcDataReader.GetValues(Object[] values)
Problem: The issue seems to occur when the GetColAttribute method returns a negative integer, which is then interpreted as a 32-bit integer in the GetSqlType method, causing an overflow. On a 64-bit Windows system with a 64-bit ODBC driver, certain calls to GetColAttribute return negative integers (e.g., -5), which triggers the exception.
Proposed Solution: To resolve this issue, I suggest interpreting the value returned by GetColAttribute as a 64-bit integer before casting it to a 32-bit integer, as shown below:
This prevents the exception by ensuring that the negative value is correctly converted.
Additional Details:
Operating System: 64-bit Windows
ODBC Driver: 64-bit for HFSql (PC Soft)
Environment: Using OdbcCommand and OdbcDataReader to access an HFSql database
Expected Behavior: The expected behavior is that the GetSqlType method works correctly without causing an integer overflow exception, even when the value returned by GetColAttribute is negative.
Thank you for your help in resolving this issue.
The text was updated successfully, but these errors were encountered:
I am encountering a System.OverflowException when executing the System.Data.Odbc.OdbcDataReader.GetSqlType(int i) method in my code. The error occurs specifically when the result of the GetColAttribute method is a negative integer, which happens with the 64-bit ODBC driver used to access an HFSql database (PC Soft).
Here is the exception I am encountering:
Proposed Solution: To resolve this issue, I suggest interpreting the value returned by GetColAttribute as a 64-bit integer before casting it to a 32-bit integer, as shown below:
Replace :
info._dbtype = unchecked((ODBC32.SQL_TYPE)(int)GetColAttribute(i, ODBC32.SQL_DESC.CONCISE_TYPE, ODBC32.SQL_COLUMN.TYPE, ODBC32.HANDLER.THROW));
By :
info._dbtype = unchecked((ODBC32.SQL_TYPE)(int)(long)GetColAttribute(i, ODBC32.SQL_DESC.CONCISE_TYPE, ODBC32.SQL_COLUMN.TYPE, ODBC32.HANDLER.THROW));
This prevents the exception by ensuring that the negative value is correctly converted.
Additional Details:
Operating System: 64-bit Windows
ODBC Driver: 64-bit for HFSql (PC Soft)
Environment: Using OdbcCommand and OdbcDataReader to access an HFSql database
Expected Behavior: The expected behavior is that the GetSqlType method works correctly without causing an integer overflow exception, even when the value returned by GetColAttribute is negative.
Thank you for your help in resolving this issue.
The text was updated successfully, but these errors were encountered: