473,563 Members | 2,767 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 VizualizareProd use : System.Web.UI.P age
{
protected SqlConnection con;//conexiunea spre baza de date

protected void Page_Load(objec t sender, EventArgs e)
{
if (IsPostBack == false)
{
string ConnectionStrin g =
WebConfiguratio nManager.Connec tionStrings["companieConnec tionString"].ConnectionStri ng;
con = new SqlConnection(C onnectionString );

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 1346
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*********@di scussions.micro soft.com> wrote in message
news:F9******** *************** ***********@mic rosoft.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 VizualizareProd use : System.Web.UI.P age
{
protected SqlConnection con;//conexiunea spre baza de date

protected void Page_Load(objec t sender, EventArgs e)
{
if (IsPostBack == false)
{
string ConnectionStrin g =
WebConfiguratio nManager.Connec tionStrings["companieConnec tionString"].ConnectionStri ng;
con = new SqlConnection(C onnectionString );

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
14503
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 for slowness. Once I'm connected the queries work pretty much instantanously but to connect using SQLPLUS, Toad, ODBC, OLEDB all take about 10...
4
6758
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 again, for a few more hours and then we have the same problem. Someone suggested adding ";Network Library=DBMSSOCN" to our connection strings. I've...
1
4494
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 reuse in the same manner provided by DB2 Connect or Websphere (or some 3rd party connection interfaces)? If DB2 V8 does have connection reuse,...
35
11365
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 Then CType(cn, IDisposable).Dispose() End If I have to admit, I'm not sure what happens here. Will someone explain this line of code (the...
4
4138
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 transaction As SqlTransaction, _ ByVal spName As String, _ ByVal ParamArray parameterValues() As Object)
5
23989
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 development client. Bur Its gives me following error message. I searched lots of things on net and tried on remote server but i didnt got suceess. Can any...
16
2853
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 a worker thread that would execute the db commands. The pool was fixed and all the connections were created when the db access class was...
20
3252
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 many connection has been used ? 2. If the maximum pool size has been reached, what happens when I call the method Open to open the connection ? Will I...
1
5106
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 the control unit and store them into the Sql server - The operation console then retrieve this data from the sql for reporting and statistics...
0
7665
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5213
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2082
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 we have to send another system
1
1200
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.