Solved

Oracle connection/session not closing

Posted on 2012-03-14
2
966 Views
Last Modified: 2012-03-15
Following a .net query of an Oracle DB, I issue a conn.close command, but the application session in Oracle remains active until the application is closed.  How do I end the connection and Oracle session once I have retrieved the results of the query?
0
Comment
Question by:mdreed
2 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37723215
Are you disposing of the reference once you have closed the connection? Also, are you using connection pooling?
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 37723419
ADO.NET uses a mechanism called connection pooling. When you call Close on a connection object, the physical connection on the server is not closed immediately. It is held open for a certain period, 5 minutes by default for SQL Server, I suppose it is of the same order for Oracle.

If you reopen a connection object with the exact same connectionstring during that timeout period, the same connection is reused. The connection is really closed if you do not use the connection during that time, or if you close the application.

This is actually a good thing.

Before .NET, we used to keep a connection opened as long as the application was active, through a public (global) object. A very bad thing that often caused problems.

It is always better to use local variables when possible. This means that you would normally need to open and close a connection in each method that needs one, even when methods are called in a loop or recursively. This would be very painful on the server, because a opening and closing a connection requires a lot of work (validating the user, managing the users pool, etc.).

Connection pooling is a good compromise.

If you really do not want connection pooling to be active, look through the documentation for your Oracle library. The pool can usually be controlled by specific indications in the connection string.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

809 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