473,386 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

SqlConnection sqlCon.Close () doent seem to work

I am using MS Application Block code, have writtent the following code:
===========================================
using (SqlConnection sqlCon = new SqlConnection ("SomeConnstring"))
{
string strQuery = @"SELECT count(*) FROM MyTable";
iCount = Convert.ToInt32 (SqlHelper.ExecuteScalar
(sqlCon,CommandType.Text, strQuery));
sqlCon.Close ();
}
===========================================

Although here, the connection is being closed and subsequently disposed in
the using {} block, this doesnt seem to work in an asp.net page and after
some time it gives an error saying that not enough conenctions in the
connection pool.

However the same code seems to work just fine in a windows form application .

How come? Is it a known issue with asp.net / iis that it connection pools
are not freed on time?
Any clues????

Nov 23 '05 #1
1 1921
I am not sure abt "using ( { " works on disposing connection..

But if you change it to following.. it works well..

//sqlCon
try
{
// open sqlCon
}
catch()
{
}
finally
{
// close sqlCon
//dispose sqlCon
}
"Ajay Bhons" wrote:
I am using MS Application Block code, have writtent the following code:
===========================================
using (SqlConnection sqlCon = new SqlConnection ("SomeConnstring"))
{
string strQuery = @"SELECT count(*) FROM MyTable";
iCount = Convert.ToInt32 (SqlHelper.ExecuteScalar
(sqlCon,CommandType.Text, strQuery));
sqlCon.Close ();
}
===========================================

Although here, the connection is being closed and subsequently disposed in
the using {} block, this doesnt seem to work in an asp.net page and after
some time it gives an error saying that not enough conenctions in the
connection pool.

However the same code seems to work just fine in a windows form application .

How come? Is it a known issue with asp.net / iis that it connection pools
are not freed on time?
Any clues????

Nov 23 '05 #2

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

Similar topics

1
by: Donnie Darko | last post by:
I'm trying to understand SqlConnection(), SqlCommand() For example. I use SqlConnection() as a parameter when I create a new SqlCommand. Then I open SqlConnection(), then I execute the...
1
by: huzz | last post by:
I have a method that gets sqldatareader as shown below.. my question is how do i close the sqlconnection (objConn) object within this method? If i put the objconn.Close(); after the return then i...
4
by: The Coolest Dolphin | last post by:
Hi all, I have a question/problem concerning usage of my sqlconnection throughout my program. In my main form (frmMain) I defined an sqlconnection (I've set the connection public so that I can...
1
by: Nayt Grochowski | last post by:
Does anyone see any problem with the loading a SqlConnection into the System.Web.HttpContextCurrent.Items collection in a Page's Constructor. Then Closing and Disposing of it the OnUnload method? ...
11
by: Bob | last post by:
In our new .NET web applications, we try to limit the use of SqlConnection to just one instance per page, even if there are multiple accesses to various queries. The thinking behind is that this...
3
by: Catadmin | last post by:
Hello, Everyone. I have a strange one here. I'm a DBA with relatively low program experience. Recently I was given an assignment to locate why our SQL Server has "orphaned" connections. The...
4
by: Steve Richter | last post by:
I really miss c++ .... I have an SqlConnection object within my Web.UI.Page object. The thinking is that the connection to the database server is opened once when the page starts to do its...
4
by: Victor | last post by:
Hi Guys I have a problem here. I want to improve the performance for a website. When I looked into the system, I have found that the system made the "SqlConnection Object" static. That mean only...
5
by: fniles | last post by:
I am using VB.NET 2003. When using SQLClient.SQLConnection with SQL 2005 database, 1. connection pooling is automatically used, right ? I mean, in the connection string I do not need to explicitly...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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...
0
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
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...

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.