?
Solved

Oracle connection/session not closing

Posted on 2012-03-14
2
Medium Priority
?
1,023 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
[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 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 1500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
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…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

743 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