To close or not to close an Oracle Connection?
NickName:Ewerton Ask DateTime:2012-04-12T23:20:16

To close or not to close an Oracle Connection?

My application have performance issues, so i started to investigate this from the root: "The connection with the database".

The best practices says: "Open a connection, use it and close is as soon as possible", but i dont know the overhead that this causes, so the question is:

1 -"Open, Use, Close connections as soon as possible is the best aproach using ODP.NET?"

2 - Is there a way and how to use connection pooling with ODP.NET? I thinking about to create a List to store some connections strings and create a logic to choose the "best" connection every time i need. Is this the best way to do it?

Copyright Notice:Content Author:「Ewerton」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/10126623/to-close-or-not-to-close-an-oracle-connection

Answers
Christian Shay 2012-04-14T20:02:06

Here is a slide deck containing Oracle's recommended best practices:\n\nhttp://www.oracle.com/technetwork/topics/dotnet/ow2011-bp-performance-deploy-dotnet-518050.pdf\n\nYou automatically get a connection pool when you create an OracleConnection. For most middle tier applications you will want to take advantage of that. You will also want to tune your pool for a realistic workload by turning on Performance Counters in the registry.\n\nPlease see the ODP.NET online help for details on connection pooling. Pool settings are added to the connection string.\n\nAnother issue people run into a lot with OracleConnections is that the garbage collector does not realize how truly resource intensive they are and does not clean them up promptly. This is compounded by the fact that ODP.NET is not fully managed and so some resources are hidden from the garbage collector. Hence the best practice is to Close() AND Dispose() all Oracle ODP.NET objects (including OracleConnection) to force them to be cleaned up.\n\nThis particular issue will be mitigated in Oracle's fully managed provider (a beta will be out shortly)\n\n(EDIT: ODP.NET, Managed Driver is now available.)\n\nChristian Shay\n\nOracle",


Cezar Schwartz 2012-04-12T16:58:13

The ODP.NET is a data provider for ADO.NET.\nThe best practice for ADO.Net is Open, Get Data (to memory), close, use in memory data.\nFor example using a OracleDataReader to load data in a DataTable in memory and close connection.\n\n[]'s",


More about “To close or not to close an Oracle Connection?” related questions

Disable oracle autocommit on close connection

I have a question about Oracle autocommit on close connection event. Information from oracle docs(http://docs.oracle.com/cd/E16655_01/java.121/e17657.pdf): If the auto-commit mode is disabled ...

Show Detail

Oracle Connection close issue with oracle 12c

I am using java 1.8 and oracle 12c versions in my application. As part of this I have below code to close the statement. protected static void close(Statement p_stmt) th...

Show Detail

Close Oracle database connection

I am new to unix shell scripting and need a suggestion. I have shell script which connects to the oracle db fetch the value and assign it outpt variable as mentioned below. outpt=$(sqlplus Usern...

Show Detail

Close Oracle database connection

I am new to unix shell scripting and need a suggestion. I have shell script which connects to the oracle db fetch the value and assign it outpt variable as mentioned below. outpt=$(sqlplus Usern...

Show Detail

To close or not to close an Oracle Connection?

My application have performance issues, so i started to investigate this from the root: "The connection with the database". The best practices says: "Open a connection, use it and close is as soon...

Show Detail

open/close an oracle connection multiple times c#

In my business logic, I use multiple oracle query's multiple times. What is the best way to open and close the oracle connection? private void update() { OracleConnection con = new OracleConn...

Show Detail

When to close Oracle database connection at nodejs?

I'm using a Nodejs app to connect a +20K users of a mobile app to an Oracle database. I establish a pool of 16 connections at process startup and destroy them at process termination. To be efficien...

Show Detail

How to close DB2 and Oracle DB connection in RobotFramework

I was trying to close an open DB2 connection for one of my automation script in robot-framework so that I can open a Oracle DB connection and perform certain task. I tried using inbuilt function pr...

Show Detail

Cannot close Oracle connection from WebSphere datasource

I try to connect to Oracle database (check connection status). I'm using following code, which works fine. public String getDatabaseStatus() { Connection conn; try { conn = DriverM...

Show Detail

NodeJS : What happen if not close oracle connection

I'm building a NodeJS Application that will connect to an oracle Database. I'm wondering what happen if I don't close connection and I call the fiftycent() function many times ? var i=50; function

Show Detail