Results 1 to 4 of 4

Thread: Detect there is already an open OleDbDataReader associated with OleDbCommand

  1. #1

    Thread Starter
    Lively Member roglopes's Avatar
    Join Date
    Sep 2002
    Location
    Brazil
    Posts
    113

    Detect there is already an open OleDbDataReader associated with OleDbCommand

    Is It possible to detect there is already an open OleDbDataReader associated with OleDbCommand?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Detect there is already an open OleDbDataReader associated with OleDbCommand

    If there's a DataReader open it's because you called ExecuteReader on a Command so you should know already. Also, once ExecuteReader returns there is no longer any association between the Command and the DataReader. There is an association between the DataReader and the Connection, because the Connection is used to retrieve the data contained in the DataReader's result set. You could check out the State property of the Connection but I don't think it will tell you nay more than Open or Closed at this point.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member roglopes's Avatar
    Join Date
    Sep 2002
    Location
    Brazil
    Posts
    113

    Re: Detect there is already an open OleDbDataReader associated with OleDbCommand

    jmcilhinney,

    I know if I call ExecuteReader the DataReader is executing, the question is different.
    I want to "share" the Command object and I "send" this Command to many instances and with 1 Command I execute many operations in many instances.
    If I use a DataReader in an instance and I use the same Command in other instance, I want to know If this Command has a DataReader associated, but the Command object doesn't have any Property that inform this.
    Do you understand me?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Detect there is already an open OleDbDataReader associated with OleDbCommand

    As I have already said, Commands and DataReaders are not associated. You call the ExecuteReader method and it returns a DataReader. Once ExecuteReader returns the DataReader is associated with a result set in a database via a Connection. It has no idea what Command was executed to create that result set, nor does the Command know anything more about the DataReader it created. The two don't need to know anything about each other.

    You can call ExecuteQuery on the same Command a thousand times and have a thousand open DataReaders and it makes no difference to the Command. It doesn't know or care. It's job is to execute an SQL statement and create a DataReader to access the result set. Once that's done the Command washes its hands of any further responsibility.

    If you want to maintain some association between the DataReader and the Command that created it then it's up to you to do it because ADO.NET doesn't. The reason it doesn't is that there isn't really a need to. The DataReader needs the Connection exclusively. That's where there's an association.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width