DSE
asked on
already a datareader associated with this connection
Hi Experts!
"There is already a datareader associated with this connection which must be closed first"
I have some code that is fired from a timer.... because of this i cant be sure that im not using a datareader elsewhere when the timer tick occurs.
Other than keeping a boolean flag when a reader is in use, how can i detect if one is in use...
To help you understand, a pseudo idea might be... if myCommand.dataReaderInUse = true then
Regards
DSE
"There is already a datareader associated with this connection which must be closed first"
I have some code that is fired from a timer.... because of this i cant be sure that im not using a datareader elsewhere when the timer tick occurs.
Other than keeping a boolean flag when a reader is in use, how can i detect if one is in use...
To help you understand, a pseudo idea might be... if myCommand.dataReaderInUse = true then
Regards
DSE
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi, thx for your reply...
I know why this occurs, im long past the early days of having this occur under normal circumstances... here, because when my timer ticks a reader may be being used legitimately elsewhere... how can i check if its in use before i try to use another?
Regards
I know why this occurs, im long past the early days of having this occur under normal circumstances... here, because when my timer ticks a reader may be being used legitimately elsewhere... how can i check if its in use before i try to use another?
Regards
ASKER
The readers are strewn throught my app...
Ideally i need some command level checking
Ideally i need some command level checking
Create a global variable and after each datareader you open in your app set the var to true and set it to false each time you close it. In your timer event do a check on this variable.
ASKER
ye thats what im doing atm saleek... but its not ideal.. assuming there is something exposed on the command that tells you if a datareader is inuse
Well... you could use threading. Create a separate thread and create a separate connection to the reader in there.. Might work. I'll look into it.
ASKER
before we delve into intensive solutions... let me just confirm, that there is no exposed value attached to a command to say that it has a datareader associated to it?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Both reasonable workarounds... not what i was looking for in truth but nevertheless, points are deserved.
You must have a datareader open somewhere before the current operation that is being performed. Or maybe you are sharing a connection between a SqlDataAdapter and an SqlDataReader, which is a bad idea. Go throu your code again and be sure this is not the case.
regards,
KS