Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# should I keep open connection in connection pooling

Tags:

c#

database

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?

like image 214
M Naeem Ashraf Avatar asked Dec 10 '12 10:12

M Naeem Ashraf


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

What are the basics of C?

C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.


2 Answers

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.

like image 72
Oded Avatar answered Oct 13 '22 11:10

Oded


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.

like image 42
Richard Schneider Avatar answered Oct 13 '22 12:10

Richard Schneider