SqlConnection sqlCon.Close () doent seem to work

  • Thread starter Thread starter Guest
  • Start date Start date
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????
 
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

Back
Top