?
Solved

already a datareader associated with this connection

Posted on 2004-11-04
10
Medium Priority
?
405 Views
Last Modified: 2010-04-24
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
0
Comment
Question by:DSE
  • 5
  • 4
10 Comments
 
LVL 11

Expert Comment

by:Ramesh Srinivas
ID: 12491744
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
 
LVL 11

Accepted Solution

by:
Ramesh Srinivas earned 500 total points
ID: 12491787
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
 

Author Comment

by:DSE
ID: 12491795
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:DSE
ID: 12491929
The readers are strewn throught my app...

Ideally i need some command level checking
0
 
LVL 11

Expert Comment

by:Ramesh Srinivas
ID: 12492112
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
 

Author Comment

by:DSE
ID: 12492200
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
 
LVL 11

Expert Comment

by:Ramesh Srinivas
ID: 12492259
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
 

Author Comment

by:DSE
ID: 12492819
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
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 300 total points
ID: 12493232
Consider using DataSet/DataTables instead.

I know it requires more resources but your scenario dictates to use them.
0
 

Author Comment

by:DSE
ID: 12565150
Both reasonable workarounds... not what i was looking for in truth but nevertheless, points are deserved.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Suggested Courses
Course of the Month8 days, 18 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question