SqlConnection sqlCon.Close () doent seem to work

G

Guest

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????
 
G

Guest

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
}
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top