64-bit HANA ODBC driver exception System.OverflowException

Hi everyone,

Recently I ran into an issue with the HANA ODBC driver 64-bit.
At the time of writing the latest version is 2.01.47.40090.

When attempting to run a simple query such as:

SELECT * FROM OCRD

then the result is an exception thrown of type “System.OverflowException: Arithmetic operation resulted in an overflow”.

The temporary workaround for this issue is, unfortunately, using the 32-bit version of the driver.
You can do this by changing the connection string accordingly.

I’ve reported the issue to SAP and will update you with their reply once I get it.
Below you can find the code that demonstrates the issue:

class Program
{
    private static bool is64Bit = IntPtr.Size == 8;

    public static string Query
    {
        get
        {
            return @"SELECT * FROM SBODEMOCH.OCRD";
        }
    }

    static void Main(string[] args)
    {
        ConnectToData();
    }

    public static void ConnectToData()
    {
        var conn = new System.Data.Odbc.OdbcConnection();

        if(is64Bit)
            conn.ConnectionString = "DRIVER={HDBODBC};UID=USER;PWD=****;SERVERNODE=server:30015;DATABASE=SBODEMOCH";
        else
            conn.ConnectionString = "DRIVER={HDBODBC32};UID=USER;PWD=****;SERVERNODE=server:30015;DATABASE=SBODEMOCH";

        try
        {                
            var command = new System.Data.Odbc.OdbcCommand(Query, conn);

            conn.Open();
            var dataSet = new System.Data.DataTable();
            dataSet.Load(command.ExecuteReader());

            Debug.WriteLine(dataSet.Rows.Count + " rows");
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex);
        }
        finally
        {
            conn.Close();
        }
    }
}

UPDATE 1:
Figured out that the column Attachment is the responsible for the exception. SELECT Attachment FROM OCRD triggers an exception on the 64-bit driver but not on 32-bit driver

UPDATE 2:
Seems that casting the value to an NVARCHAR datatype will allow you to perform the query without the exception being thrown. However, this workaround won’t work if you are using the ‘*’.

Leave a Reply

Your email address will not be published. Required fields are marked *