Solved

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

Posted on 2009-03-30
4
1,454 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
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
I think that we always must open and close the connection.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article describes some very basic things about SQL Server filegroups.
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now