?
Solved

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

Posted on 2009-03-30
4
Medium Priority
?
1,483 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 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

771 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