views:

23

answers:

2

Hello

I create SqlConnection objects in every Insert,Update,Delete and Select methods in asp.net web pages. Then i close the connection objects in finally block. But im not sure about this is a good way. Is this a problem about connection pool?

Do you have any recommendations about how to use SqlConnection and SqlDataReader objects for me?

Thanks.

A: 

Closing the connection in the finally block is what you want to do. An alternative would be to use the Using statement. Using will work with any object that implements iDisposable including sqlconnection and will call dispose on the object on completion regardless if there was an exception.

Mike
A: 

If you are definitely closing off your SQLConnection then I would also review your SQLDataReader and ensure you are closing those.

BradB