OracleConnection

P

Peter K

Hi - is it the case that OracleConnection does not call close when the
connection is disposed?

For example, I use this sort of construct:

using (OracleConnection conn = GetConnection())
{
using (OracleTransaction tx = conn.BeginTransaction())
{
using (OracleCommand command = conn.CreateCommand())
etc.

But now a colleague tells me that the connection is not closed when the
using clause ends. Can this be true? Is that not a serious bug in
OracleConnection?

Or could it be affected by the "GetConnection" method which is a call to a
third-party class which actually gives us a connection - I mean, could
GetConnection somehow affect the subsequent "dispose" behaviour of the
connection?

Thanks,
Peter
 
N

Nicholas Paldino [.NET/C# MVP]

Peter,

What makes you think that it is not being closed? If you are using
connection pooling, then you might see the connection open still (not to
your code through the OracleConnection class, but through a performance
counter, for example). Other than that, the code you wrote will call the
Dispose method on the connection, which will close the connection.
 
P

Peter K

Peter,

What makes you think that it is not being closed? If you are
using
connection pooling, then you might see the connection open still (not
to your code through the OracleConnection class, but through a
performance counter, for example). Other than that, the code you
wrote will call the Dispose method on the connection, which will close
the connection.

Hi thanks, these were also my thoughts. I have no evidence that
OracleConnection does not behave as expected - a colleague has just told me
I need to explictly close my connections because OracleConnection does not
function correctly on a dispose (ie at the end of a using clause).

I have not yet heard back from him about how he has ascertained this.
 
N

Nicholas Paldino [.NET/C# MVP]

Peter,

Looking in Reflector, I don't see how that is possible. Also, none of
the documentation indicates that the behavior is outside of what is to be
expected, that when Dispose is called, the connection is closed.
 
F

Frans Bouma [C# MVP]

Peter said:
Hi - is it the case that OracleConnection does not call close when
the connection is disposed?

For example, I use this sort of construct:

using (OracleConnection conn = GetConnection())
{
using (OracleTransaction tx = conn.BeginTransaction())
{
using (OracleCommand command = conn.CreateCommand())
etc.

But now a colleague tells me that the connection is not closed when
the using clause ends. Can this be true? Is that not a serious bug in
OracleConnection?

Or could it be affected by the "GetConnection" method which is a call
to a third-party class which actually gives us a connection - I mean,
could GetConnection somehow affect the subsequent "dispose" behaviour
of the connection?

ODP.NET or MS Oracle client?

ODP.NET has a lot of tiny little quircks, like calling Dispose on
every element or else you'll have memory leaks etc. Though I don't
think any ADO.NET provider leaves a connection open when dispose is
called, simply because the connection has to be cleaned up to make
dispose do its job :)

Closing a connection will make it go to the pool, which means the
connection physically stays open for some time. Perhaps your collegue
meant that, although with close you can't change that behavior. (nor
should you want to)

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
P

Peter K

ODP.NET or MS Oracle client?

ODP.NET has a lot of tiny little quircks, like calling Dispose on
every element or else you'll have memory leaks etc. Though I don't
think any ADO.NET provider leaves a connection open when dispose is
called, simply because the connection has to be cleaned up to make
dispose do its job :)

Closing a connection will make it go to the pool, which means the
connection physically stays open for some time. Perhaps your collegue
meant that, although with close you can't change that behavior. (nor
should you want to)

Hi there

We are using Oracle.DataAccess.Client.OracleConnection.

I wasn't really aware of the different connection objects one could use. Do
you have references to the different types?

Thanks,
Peter
 
F

Frans Bouma [C# MVP]

Peter said:
Hi there

We are using Oracle.DataAccess.Client.OracleConnection.

I wasn't really aware of the different connection objects one could
use. Do you have references to the different types?

You're using ODP.NET, which is preferable over Microsoft's own Oracle
ADO.NET client in .NET. ODP.NET is released by Oracle, and has more
features. The only downside is that it's still a wrapper around its own
Java based CLI, so you do have to call Dispose() on OracleParameter
objects for example otherwise you'll get memory leaks

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Frans said:
You're using ODP.NET, which is preferable over Microsoft's own Oracle
ADO.NET client in .NET. ODP.NET is released by Oracle, and has more
features. The only downside is that it's still a wrapper around its own
Java based CLI, so you do have to call Dispose() on OracleParameter
objects for example otherwise you'll get memory leaks

Java based CLI ??

Do you mean native OCI ?

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top