Solved

Oracle connection/session not closing

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

777 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