Oracle Data Provider for .NET and Disposing of DbCommand and Parameters

There are quite a few examples of using Microsoft's Enterprise Library Data Access Block that does not illustrate calling Dispose on the DbCommand and Parameters collection.  When working with ODP.NET it is a recommended best practice to explicitly dispose of both. For the DBCommand, a "using" block is a good choice as once out of scope, Dispose will always be called.

In terms of parameters, the following example can be used to ensure they are cleaned up:

foreach (OracleParameter p in cmd.Parameters)
{
if (p.Value is IDisposable)
{
((IDisposable)(p.Value)).Dispose();
}
((IDisposable)p).Dispose();
}

 

Oracle Data Provider for .NET and Disposing of DbCommand and Parameters

There are quite a few examples of using Microsoft's Enterprise Library Data Access Block that does not illustrate calling Dispose on the DbCommand and Parameters collection.  When working with ODP.NET it is a recommended best practice to explicitly dispose of both. For the DBCommand, a "using" block is a good choice as once out of scope, Dispose will always be called.

In terms of parameters, the following example can be used to ensure they are cleaned up:

foreach (OracleParameter p in cmd.Parameters)
{
if (p.Value is IDisposable)
{
((IDisposable)(p.Value)).Dispose();
}
((IDisposable)p).Dispose();
}