We've recently run into some issues using the SqlAnywhere reader for our .Net application. We have a recursive reader which fetches several different accounts. We've noticed that whenever the number of accounts reaches exactly 20, the reader suddenly fails at the reader.Read() throwing the following error:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
If we remove the recursive aspect, the reader is capable of continuing on without failing. Below is our while code. If you need any additional information, please don't hesitate to ask Thank you!
try
{
var command = new SACommand(sqlQuery.ToString(), _connection);
command.Parameters.AddWithValue(q.First().column, cKey);
var reader = command.ExecuteReader();
var x = 0;
// this is where it fails after the 20th entry is added to the newList
while (reader.Read())
{
x++;
var trueType = Type.GetType(objectType);
if (trueType == null) continue;
var obj = Activator.CreateInstance(trueType);
var j = 0;
foreach (var i in q)
{
var propertyInfo = trueType.GetProperty(i.name);
AssignPropertyValue(obj, i.type, reader, j++, propertyInfo);
}
// extract the join columns if they exsist
foreach (var i in @join)
{
var propertyInfo = trueType.GetProperty(i.name);
AssignPropertyValue(obj, i.type, reader, j++, propertyInfo);
}
// This is the recursive bit that causes the while statement to run again.
if (!baseOnly)
{
DataMapperHelper.InitializeBags(this, cKey, xml.Descendants("bag"), xml, ref obj);
DataMapperHelper.InitializeManyToOne(this, xml.Descendants("many-to-one"), xml, ref obj);
}
if (newList != null) newList.Add((T)obj);
}
}
catch (Exception ex)
{
throw ex;
}