Solved

Oracle connection/session not closing

Posted on 2012-03-14
2
930 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 74

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

747 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