I have a single threaded application that needs to call a sub multiple times passing it different arguments each time. The only problem is that the sub opens a data reader and reads data from a database (using the passed argument). That works fine, but the read operation takes a few seconds, so the second call to the sub throws an error "there is already an open datareader associated with this connection".
Without redesigning my whole app, is there something I'm missing where I need to do something with the datareader to allow multiple reads to happen simultaneously?
Thanks.
For example:
For x as integer = 0 to 10
dim id as integer = my_sub(x)
Next X
Private function my_sub(x)
dim return_value as integer = 0
my_reader = sqldatareader
db.cmd.CommandText = "select id from database where id = " & x
my_reader = db.cmd.ExecuteReader
my_reader.Read()
If my_reader.HasRows Then
return_value = my_reader(0)
End If
my_reader.Close()
Return return_value
End Sub