Solved

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

Posted on 2009-03-30
4
1,463 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql script with strange password string 1 43
MySQL-Design Help 12 41
Database Owner 3 20
Delete old Sharepoint backups 2 21
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
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…

749 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