walterhuang
walterhuang

Reputation: 632

OdbcDataAdapter Fill throws OverflowException Arithmetic operation resulted in an overflow

I try to retrieve data from db2 using OdbcDataAdapter and this code works perfectly in my old machine (Windows 7 32 bit, VS2010)

public DataSet GetDataSet(string sql, string connstr)
{
    using (OdbcConnection cn = new OdbcConnection(connstr))
    {
        using (OdbcCommand cmd = new OdbcCommand(sql, cn))
        {
            OdbcDataAdapter adapter = new OdbcDataAdapter(cmd);
            DataSet ds = new DataSet();
            adapter.Fill(ds);
            return ds;
        }
    }
}

However, when I start a new project in my new machine (Windows 64 bit, VS2013) using the same code. I got exception when executing adapter.Fill(ds)

System.OverflowException
Arithmetic operation resulted in an overflow.

I have no clue because the same code and sql query works on my old machine. Any suggestions will be appreciated.

StackTrace

 at System.Data.Odbc.OdbcDataReader.GetSqlType(Int32 i)
 at System.Data.Odbc.OdbcDataReader.GetFieldType(Int32 i)
 at System.Data.ProviderBase.SchemaMapping.SetupSchemaWithoutKeyInfo(MissingMappingAction mappingAction, MissingSchemaAction schemaAction, Boolean gettingData, DataColumn parentChapterColumn, Object chapterValue)
 at System.Data.ProviderBase.SchemaMapping..ctor(DataAdapter adapter, DataSet dataset, DataTable datatable, DataReaderContainer dataReader, Boolean keyInfo, SchemaType schemaType, String sourceTableName, Boolean gettingData, DataColumn parentChapterColumn, Object parentChapterValue)
 at System.Data.Common.DataAdapter.FillMappingInternal(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 schemaCount, DataColumn parentChapterColumn, Object parentChapterValue)
 at System.Data.Common.DataAdapter.FillMapping(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 schemaCount, DataColumn parentChapterColumn, Object parentChapterValue)
 at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
 at System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
 at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
 at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
 at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)

Upvotes: 0

Views: 3221

Answers (2)

Ryan Gibbs
Ryan Gibbs

Reputation: 1320

I recently ran into the same or similar problem. I was relatively positive it wasn't related to to the 32 VS 64 bit issue, despite that being the solution that came up with all my searches.

As it turned out, at least in my instance, that wasn't what caused it.

The database (MYSQL) that my odbc adaptor was reading from had been recently modified to include a new column that was set up with the 'TINYINT' type, which I gather was supposed to be the equivalent of a boolean. This datatype is what was causing the exception.

Upon switching the datatype of that column in the database to 'INT' instead of 'TINYINT' the exception was relieved and the site worked normally.

I thought I would post this reply as another avenue for anyone else that happened to run into this issue due to a similar change.

Upvotes: 0

PGP_Protector
PGP_Protector

Reputation: 228

Was having the same issue with my project

On my 64Bit system I'd get the same error, query ran fine in SQL, no data out of bounds.

Only solution I found so far was to build the application as a 32 bit application (this solved the error for me)

Upvotes: 1

Related Questions