Solved

CLose a connection?

Posted on 2006-11-06
3
410 Views
Last Modified: 2008-03-06
You have an application that accesses a SQL Database utilizing the following code:

SqlConnection nwindConn = new SqlConnection("Data Source=localhost;
Integrated Security=SSPI; Initial Catalog=northwind");
nwindConn.Open();

What should you do to end the use of this Data Connection once you are finished with it?

Do nothing since the connection will be closed when Garbage Collection is performed on your object.
 
 
--------------------------------------------------------------------------------
 
  Close the connection directly by calling "nwindConn.Close();".
 
 
--------------------------------------------------------------------------------
 
  Close the connection directly by calling "nwindConn.Open = False;".
 
 
--------------------------------------------------------------------------------
 
  Do nothing because the connection is closed immediately after you pull data from the SQL Database.
 

0
Comment
Question by:mathieu_cupryk
  • 2
3 Comments
 
LVL 35

Expert Comment

by:Raynard7
ID: 17885756
Hi,

This depends if you have connection pooling enabled on your connection.

Garbage collection will not clean up a pooled connection -

alternativley I'd reccomend that you always close nwindConn.Close(); partially because your database may have a connection limit and if you are not utilising it then without calling that you are taking up an active connection.
0
 
LVL 15

Accepted Solution

by:
ozymandias earned 250 total points
ID: 17885757
Close the connection directly by calling "nwindConn.Close();".
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17885783
How was my answer wrong? i said to call nwindConn.Close()
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

9 Experts available now in Live!

Get 1:1 Help Now