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

by Cliff 4. October 2012

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

by Cliff 4. October 2012

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();
}

 

Cliff Gray's Info

Cliff Gray
Developer/Founder GrayTechnology.com.

E-mail me Send mail

Authors

Calendar

<<  June 2017  >>
MoTuWeThFrSaSu
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

View posts in large calendar

Blogroll

Download BlogEngine.NET

Download at CodePlex

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2017

Subscribe