473,500 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Connection problem

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
Jun 20 '06 #1
1 1336
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 :).
"Horia Demian" <Ho*********@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...
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

Jun 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
14493
by: Harry | last post by:
Using Oracle 8i enterprise on win 2000 (sp3) Installed the standard configuration & whenever I make a connection it takes about 10 secs. It's running on a P1900 with 1gb Ram so no reason there...
4
6750
by: James | last post by:
We've had a recurring problem where all of a sudden we get a DBMSSOCN General Network Error on any page that connects to SQL Server. Then we have to reboot the server and everything works fine...
1
4487
by: Mark | last post by:
I know that DB2 LUW version 8 has "connection pooling" that provides a connection concentrator (limits the number of simultaneous connections that can occur). But does it really provide connection...
35
11335
by: Eric Sabine | last post by:
In my Finally block, I was using cn.close (where cn is an ADO.NET connection object, SQLConnection to be exact) and then I came across the following in some microsoft code. If Not cn Is Nothing...
4
4134
by: Rahul Anand | last post by:
Getting SQL Exception when trying to implement Connection based Trasaction using SQL Helper class. I am using the follwing function to execute my stored procs: -=-=-=- ExecuteScalar(ByVal...
5
23976
by: Suresh | last post by:
Hi Guys I have Db2 server installed on remote server. i am connecting to that remote server by using VPN. I want to connect that remote DB2 server instance using my local machine DB2...
16
2842
by: crbd98 | last post by:
Hello All, Some time ago, I implemented a data access layer that included a simple connectin pool. At the time, I did it all by myself: I created N connections, each connection associated with...
20
3239
by: fniles | last post by:
I am using VS2003 and connecting to MS Access database. When using a connection pooling (every time I open the OLEDBCONNECTION I use the exact matching connection string), 1. how can I know how...
1
5100
by: sherifbk | last post by:
Problem description ============== - I have 4 clients and 1 server (SQL server) - 3 clients are Monitoring console 1 client is operation console - Monitoring console collects some data from...
0
7149
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7207
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7242
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7401
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5503
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4928
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4619
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1434
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
686
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.