Reputation: 2655
I am having an MVC3 + Entity Framework 4.1 app, currently iam testing it locally on my pc.
I want to know whether i have closed all my connections properly by disposing entities context or not. Also is there any available method thru which i can see how many connections are currently open. I am afraid i am not closing all my open connections properly.
Or is there any other way to check whether through my web app i am closing all my db connections properly or not
Upvotes: 1
Views: 2561
Reputation: 1038770
With ADO.NET normally you do not open/close physical database connections manually. There is a connection pool handled by the framework. So when you do new SqlConnection
you are not opening a new physical connection to the database, you are simply drawing one from the pool. And when you call connection.Close
you are not closing the connection, you are simply returning it to the connection pool so that it can be reused.
So what is important for you is to ensure that your code holds connections for as short time as possible and return them to the pool as fast as possible. You may take a look at the following article which goes into more details about connection pooling.
Upvotes: 4