M Naeem Ashraf
M Naeem Ashraf

Reputation: 241

C# should I keep open connection in connection pooling

I am working on multi threaded application(a server) where I used to handle 2000 clients at a time and I am opening separate database connection of MySQL database in each thread. So I have enabled the connection pooling. I searched on many blocks that after using connections we should close it then it will return back to pool and will be used by other thread. on the other hand we know that connection making is a time consuming process. So my question is why should we close connection in connection pooling. and what is better keep connection open or close them?

Upvotes: 6

Views: 867

Answers (2)

Richard Schneider
Richard Schneider

Reputation: 35477

When you 'Close' a connection that is pooled;You are saying that you are done with the connection and the pool can use it again.

Calling Close does not physically tear down the connection. The pool has its own logic to determine when connections are physically closed.

Upvotes: 1

Oded
Oded

Reputation: 499002

we know that connection making is a time consuming process

Correct - that's why we have connection pools. They maintain connections, so you don't create new ones.

why should we close connection in connection pooling

So they are returned to the pool to be used by other threads.

Connections are expensive resources, so you want to open, use and close them as quickly as possible, so they will return to the pool and be available to other threads.

Upvotes: 6

Related Questions