?
Solved

C# Oracle provider ODP.NET : close connection in finaly

Posted on 2009-03-30
4
Medium Priority
?
1,520 Views
Last Modified: 2013-12-17
I write a unique class fro my C# web application to open the connection to a oracle 10 database. I want to use Oracle provider ODP.NET for this.
With ADO.NET It was better to close the connection in the finally. It's still right with ODP.NET and Visual studio 2008 (framework 3.5)? By default, connection pooling is used, I must  close the connection in the finaly?

Thanks for your help.

Angie
0
Comment
Question by:AngieWill
  • 2
  • 2
4 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 24022121
Yes. Regardless of the provider you are using you need to close the connection when you are finished with it. The safest place to do this is in a finally block as it will then get executed regardless of whether or not an exception occurs.
0
 

Author Comment

by:AngieWill
ID: 24026009
I read a note in msdn site:
 Do not call Close or Dispose on a Connection, a DataReader, or any other managed object in the Finalize method of your class. In a finalizer, only release unmanaged resources that your class owns directly. If your class does not own any unmanaged resources, do not include a Finalize method in your class definition.

conn.close() must be called after the block try...catch?
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 1500 total points
ID: 24026526
That MSDN note is talking about something slightly different. A finalizer is a destrcutor on an object that is called when the object is cleaned up by the GC. You have no control over when the GC will clear up your object, so therefore no idea when the Finalizer wil be called. So if you have a connection that you try to close in the Finalizer then your connection will be left open until the object is destroyed.

So, as I said earlier, you need to close the connection when you are finished using it, usually in teh "finally" block of a try catch statement.
0
 

Author Closing Comment

by:AngieWill
ID: 31564356
I think that we always must open and close the connection.
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question