I am writing a recursive function that loops over some query results and builds a string. The function simply uses the same connection global connection object and instantiates new query and reader objects each call. The queries are being executed fine, so this is not an issue with having more than one command object per connection object (I saw many google results about this issue). The problem I am encountering is that the Read function call, on the reader object, is not iterating to the next item in the query result. It's like the child recursive calls are messing with the parent's reader object. Does anyone know why this might be occurring? An example pseudo-code follows:
Code: Select all
private string foo(int id, string path)
{
SqlCommand the_command = "SELECT id, directory FROM table WHERE id = :id"
the_command.connection_object = g_GlobalConnection
SqlReader the_reader = the_command.execute()
while (the_reader.Read())
{
int child_id = the_reader.readint()
string child_path = the_reader.readstring()
foo(child_id, child_path)
}
}
Obviously this code path would not return or do anything, but it shows the flow of my function and where the child call is inside the Read loop.
Any ideas?