ODBCException thrown when checking if column IsDBNull

0

I am writing a program that reads data from one database to be inserted/updated in another. The source database will be DB2 when deployed, but at the moment I am developing using a SQL Server 2008 R2 copy.

I am using ODBC driver 11 for SQL Server to read the data and am getting an unusual exception.

My code is:

public static string ReadShortODBCColumn(OdbcDataReader reader, string columnName) 
{    
    int column = reader.GetOrdinal(columnName);
    return reader.IsDBNull(column) ? (short)0 : reader.GetInt16(column);
}

The exception that is being output is:

2013-02-06 13:09:16.7834  System.Data.Odbc.OdbcException (0x80131937)
at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
at System.Data.Odbc.OdbcDataReader.GetData(Int32 i, SQL_C sqlctype, Int32 cb, Int32& cbLengthOrIndicator)
at System.Data.Odbc.OdbcDataReader.GetData(Int32 i, SQL_C sqlctype)
at System.Data.Odbc.OdbcDataReader.internalGetInt16(Int32 i)
at System.Data.Odbc.OdbcDataReader.GetValue(Int32 i, TypeMap typemap)
at System.Data.Odbc.OdbcDataReader.GetValue(Int32 i)
at System.Data.Odbc.OdbcDataReader.IsDBNull(Int32 i)
at ProcessEngine.Business.Utilities.ReadShortODBCColumn(OdbcDataReader reader, String columnName)

But when I look at the data being retrieved, the column is not null and looks entirely normal. The only situation similar that I have been able to find online is related to SSIS, and I don't think their work arounds will apply.

Does anyone have any ideas?

sql-server-2008
c#-4.0
odbc
asked on Stack Overflow Feb 6, 2013 by Sam Banks

1 Answer

0

I didn't find an answer for this issue, but was able to work around it.

Reducing the amount of data being handled at once seems to avoid triggering the bug. For most of the tables I was transferring I could do 20,000 rows at a time. Two of the tables had to be processing in 10,000 row chunks. One table it really had trouble with had to be processed in 1000 row chunks.

answered on Stack Overflow Mar 4, 2013 by Sam Banks

User contributions licensed under CC BY-SA 3.0