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
DSEAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ramesh SrinivasTechnical ConsultantCommented:
Hi,

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
0
Ramesh SrinivasTechnical ConsultantCommented:
You could always check to see if a datareader is open. If you know which datareader it is in your app then do a check in the timer routine. Something like this in your timer:

If (DataReaderIthinkIsOpen.IsClosed) Then
    Do stuff with datareader
End If

regards,

KS
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DSEAuthor Commented:
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
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

DSEAuthor Commented:
The readers are strewn throught my app...

Ideally i need some command level checking
0
Ramesh SrinivasTechnical ConsultantCommented:
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.

0
DSEAuthor Commented:
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
0
Ramesh SrinivasTechnical ConsultantCommented:
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.
0
DSEAuthor Commented:
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?
0
Éric MoreauSenior .Net ConsultantCommented:
Consider using DataSet/DataTables instead.

I know it requires more resources but your scenario dictates to use them.
0
DSEAuthor Commented:
Both reasonable workarounds... not what i was looking for in truth but nevertheless, points are deserved.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.