Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

OracleDataReader.Close() needed to release Open Cursors

382478Dec 4 2003 — edited Aug 1 2007
I noticed that if I follow the idiom for using OracleDataReader as given in the examples that accompany ODP, it is not good enough for cleaning up.
For example, all the examples provided use something like this:
--------------
try
{
con.Open();
rdr = cmd.ExecuteReader();
...do stuff with rdr
}
finally
{
cmd.Dispose();
con.Close();
con.Dispose();
}
-----------

But that's not good enough. If I do this 20 times, I get 20 identical open cursors.
If, however, the finally block is coded like this,
-----------
finally
{
rdr.Close();
rdr.Dispose();
cmd.Dispose();
con.Close();
con.Dispose();
}
--------------
Then there are NO open cursors after this is all over with.
For Oracle people: Is this the intended behavior?
For everyone else: Where you aware you needed to do this to clean up?
I didn't know to do this since none of the examples do this.
If it turns out this is best practice for ODP, I recommend the examples be updated to do this.
If I'm misunderstanding something, then someone please educate me.

Thanks,
David Kreth Allen
Carlson School of Management
University of Minnesota
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 29 2007
Added on Dec 4 2003
7 comments
4,980 views