Reputation: 1527
I'm running into a strange corner-case while querying an iSeries server using ADO.NET and the IBM.Data.DB2.iSeries provider that comes with Client Access.
I'm running a simple query:
SELECT col FROM table WHERE (col LIKE 'value' OR col LIKE 'value%') FETCH FIRST n ROWS ONLY
But the adapter gives an IndexOutOfRange ONLY when value is, in my case, 102. Running the same query with 101 or 103 works normally. I checked the result set by running the query directly on the iSeries, it works perfectly, and the returned rows have nothing different from what I would get running the query with another value.
Pseudo-code that runs the query is as follows:
String query = '...' // See above query
IDbDataAdapter adapter = new iDB2DataAdapter(query, connection)
DataSet ds = new DataSet()
adapter.Fill(ds) // IndexOutOfRangeException only a certain values
Sample of the data that should be returned :
1023 29134
1023
1023029039
Note The blank character (and other special chars) is also found in non-failing resultsets, so I'm inclined to believe that it's not the cause of the problem.
Stack trace of the exception
at IBM.Data.DB2.iSeries.iDB2DataReader.GetDcRow(IntPtr dataPtr, Int32 row, MpDcData[] dcData, UInt32 block)
at IBM.Data.DB2.iSeries.iDB2DataReader.GetValues(Object[] values)
at System.Data.ProviderBase.DataReaderContainer.CommonLanguageSubsetDataReader.GetValues(Object[] values)
at System.Data.ProviderBase.SchemaMapping.LoadDataRow()
at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
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)
Update You guys were right, thanks for your help. After migrating the driver to v6r1 and installing all service packs, the problem did not go away. I ended up finding the corrupted data in my table by using the (third-party) PEEK utility, which complained about some characters being in an invalid range (less than x'40' or equal to x'FF'). The nice part about this tool is that automagically replaces invalid characters with '%', so I was able to locate the invalid data, which shows up as a blank in every other client/program (tried ODBC, STRSQL, UPDDTA).
The invalid character was actually a null char (x'00'), which the .NET driver does not seem to like.
Last update IBM support actually pointed me to this APAR (SE35276), which solves the issue.
Upvotes: 0
Views: 905
Reputation: 21255
Try using other query tools to see if you get errors there. I am with @Rajiv that there is some bad data in the table. And don't use the STRSQL command on the system that is less likely to have problems than other PC based tools. One I believe is called something like Squirrel.
Upvotes: 1
Reputation: 2402
The more I see the problem you are running into, the more I doubt the .net driver. I pull data across from a unix based system and frequently run into issues like this when the driver gets something its not expecting. My guess is that your row #102 has some data which either doesnt fit the buffer or has a data type that the driver does not expect to see at the source. Would you have some sample data? How about trying to pull 1 column at a time to see where it fails??
Upvotes: 2