I have an application that needs to load data from an IBM DB2 database view into a System.Data.DataTable using the Load(IDataReader reader) function. However, when data is loaded with many thousand items the reader at some point throws a NullReferenceException.
This appears to only happen on views, since loading data from a normal database table returns the data without an error.
I would expect the data from the reader to be loaded into DataTable without a NullReferenceException since any nullable columns should simply be marked as nullable in the Datatable column.
The timeout for the connection as well as for the command are set to absurd values, so the chance of the reader simply timing out should be eliminated.
Connection string:
private const string connectionString = "Provider=IBMDA400;Data Source=...;User ID=...;Password=...;Force Translate=37;Connect Timeout=600";
OleDbCommand object creation:
new OleDbCommand(query, Connection) { CommandType = CommandType.Text, CommandTimeout = 500 }.ExecuteReader();
The following picture shows the error occurring at the Load() method.
Here is the full codeblock:
var dataTable = new DataTable();
var reader = Oledb.executeQuery($"SELECT * FROM ... WHERE ...");
dataTable.Load(reader);
Oledb.executeQuerry code:
return new OleDbCommand(query, Connection) { CommandType = CommandType.Text, CommandTimeout = CommandTimeout }.ExecuteReader();
Edit:
Here is the full Stacktrace of the exception:
>System.Data.dll!System.Data.OleDb.OleDbDataReader.GetRowDataFromHandle()
System.Data.dll!System.Data.OleDb.OleDbDataReader.GetValueBinding(System.Data.OleDb.MetaData info)
System.Data.dll!System.Data.OleDb.OleDbDataReader.GetValues(object[] values)
System.Data.dll!System.Data.ProviderBase.DataReaderContainer.CommonLanguageSubsetDataReader.GetValues(object[] values)
System.Data.dll!System.Data.ProviderBase.SchemaMapping.LoadDataRow()
System.Data.dll!System.Data.Common.DataAdapter.FillLoadDataRow(System.Data.ProviderBase.SchemaMapping mapping)
System.Data.dll!System.Data.Common.DataAdapter.FillFromReader(System.Data.DataSet dataset, System.Data.DataTable datatable, string srcTable, System.Data.ProviderBase.DataReaderContainer dataReader, int startRecord, int maxRecords, System.Data.DataColumn parentChapterColumn, object parentChapterValue)
System.Data.dll!System.Data.Common.DataAdapter.Fill(System.Data.DataTable[] dataTables, System.Data.IDataReader dataReader, int startRecord, int maxRecords)
System.Data.dll!System.Data.Common.LoadAdapter.FillFromReader(System.Data.DataTable[] dataTables, System.Data.IDataReader dataReader, int startRecord, int maxRecords)
System.Data.dll!System.Data.DataTable.Load(System.Data.IDataReader reader, System.Data.LoadOption loadOption, System.Data.FillErrorEventHandler errorHandler)
System.Data.dll!System.Data.DataTable.Load(System.Data.IDataReader reader)
>ProductionRecords.dll!BbtExtensions.ProductionRecords.GetIsnrsForPon.AnonymousMethod__0() Line 205
mscorlib.dll!System.Threading.Tasks.Task<System.Threading.Tasks.Task<System.Collections.Generic.List<BbtExtensions.ProductionRecords.IsnrDto>>>.InnerInvoke()
mscorlib.dll!System.Threading.Tasks.Task.Execute()
mscorlib.dll!System.Threading.Tasks.Task.ExecutionContextCallback(object obj)
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
mscorlib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot)
mscorlib.dll!System.Threading.Tasks.Task.ExecuteEntry(bool bPreventDoubleExecution)
mscorlib.dll!System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch()
mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
