Connection problem

G

Guest

I have the following code in a web form which use a connection to SQL Server
2000. I use this form to display a list of products from a table. The
connection string to the database server is stored in web.config file.

public partial class VizualizareProduse : System.Web.UI.Page
{
protected SqlConnection con;//conexiunea spre baza de date

protected void Page_Load(object sender, EventArgs e)
{


if (IsPostBack == false)
{


string ConnectionString =
WebConfigurationManager.ConnectionStrings["companieConnectionString"].ConnectionString;
con = new SqlConnection(ConnectionString);



try
{
con.Open();

}

catch (Exception eExecutie)
{
//capturam erorile ce apar
}
finally
{

con.Close();
con.Dispose();

}

}
}


after this page is load and the line of code con.Close() is parsed the
connection to the databse server still remain open ???Why??? I tried to
eliminate the object from memory with con.Dispose(); The connection still
remain open. (This is very confused to me. Sql Server still see the
connection in Current activity node enen if I click the refresh option from
the dropdown menu)

Can anyone tell me what I am doing wrong?

Thank you very much for your time,
Horia
 
N

Norman Yuan

By default, Connection pool is enabled in ADO.NET. When your code cn.Close()
or cn.Dispose() is executed, the connection is not actaull closed, it is
handed back to the connection pool. The connection pool is actaully
cloing/opening connection if needed. Connection pooling makes database
access from application, especially ASP.NET application scalable. Google for
"Connection Pooling" gives you tons of link to study :).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top