我嘗試檢索使用OdbcDataAdapter的從DB2數據和此代碼的工作完全在我的老機器(Windows 7的32位,VS2010)OdbcDataAdapter的填寫拋出OverflowException異常算術運算導致溢出
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;
}
}
}
然而,當我使用相同的代碼在我的新機器(Windows 64位,VS2013)中啓動一個新項目。執行adapter.Fill(ds)
System.OverflowException
Arithmetic operation resulted in an overflow.
時,我不知道,因爲相同的代碼和SQL查詢的工作我的舊機器上我得到了異常。任何建議將不勝感激。
堆棧跟蹤
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)
最近我遇到了同樣的問題。可能是因爲你正在從64位運行32位ODBC驅動程序?它是否在使用iSeries適配器的DB2/400上? – 2015-01-04 07:58:17
@GuidoLeenders是的,它是DB2/400 – walterhuang 2015-06-24 06:02:46