Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

closing connection

closing connection

closing connection


is con.close() enough to close the connection ? or should I also add con.dispose() ?

I have been getting a message stating "Timeout expired. the timeout period elapsed prior to a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.

any info would be appreciated

RE: closing connection

This should not happen in newer versions of the framework since the have enhanced garbage collection. Since I don't know what version or your exact code, I suspect connections are being left open. The best thing to do is to get into the habit of using "Using" statements when opening connections to the DB. The "Using" will close the connection for you automatically once data is returned or an error occurs.

RE: closing connection

okay, I understand. is the below code fine or did I miss something. since I'm using "try" do I need to dispose or con ?

Using con As SqlConnection = New SqlConnection(My_Con)

Dim cmd As New SqlCommand

cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "My SP"


Catch ex As Exception
error handling
message to user
End Try
End If

End Using

RE: closing connection

Better use using:


using (var sqlConn = new SqlConnection(ConnectionString))
I used Close and Dispose and have troubles, but when I started to use using() the problems gone smile

Borislav Borissov
VFP9 SP2, SQL Server

RE: closing connection

okay, thanks

I thought of the whole purpose of "using" was that the connection was closed automatically and you don't need to do a con.close() ? I guess it wouldn't hurt

RE: closing connection

With a Using statement you don't need to specifically close the connection. That is the major point of using a Using statment.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close