SQLiteDataReader.Read()
doesn't reply with false even though it contains data.
The following code is what I'm doing, expected to enter the while loop in the try block.
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
{
SQLiteCommand command = new SQLiteCommand(connection);
SQLiteDataReader reader = null;
//Make sure to ignore class names below, the problem isn't related to them they are changed for sake of demonstration
Dictionary<string, SomeDTO> output = new Dictionary<string, SomeDTO>();
try
{
command.CommandText = $"SELECT * FROM {TableName}";
connection.Open();
reader = command.ExecuteReader();
while (reader.Read())
{ //This loop is never entered
output.Add(reader.GetString(0), ConvertReaderToObject(reader));
}
}
catch (Exception ex)
{
Log.Error("SOME-LOG IRRELEVANT"+ex.Message);
}
finally
{
if(reader != null)
{
reader.Close();
}
command.Dispose();
connection.Close();
}
return output;
}
}
In the picture below you can see debugger details on the reader object, data was read as expected...
I have reviewed these questions but couldn't find the answer there:
@TimSchmelter answer, posting to resolve so question won't drive attention to it.
The debugger itself consumes the data in reader
, thus I can see the data in the debugger. Debugging straight from the catch, will show I had an exception inside the while loop.