Application allowed in connection poolProgramObtain a connection from the connection pool and use the connection, without re-establishing a connection for each connection request. Once a new connection is created and placed in the connection pool, the application can reuse the connection without the entire database connection creation process.
When an application requests a connection, the connection pool allocates a connection for the application instead of creating a new connection. After the application uses the connection, the connection is returned to the connection pool instead of being released directly.
How to Implement connection pool
Make sure that each connection uses the same connection string (the same as the connection pool); only the connection pool with the same connection string will work. If the connection strings are different, the application will not use the connection pool but create a new connection.
Advantages
The main advantage of using a connection pool is performance. The time required to create a new database connection mainly depends on the speed of the network and the distance between the application and the database server (network). This process is usually a very time-consuming process. After the database connection pool is used, database connection requests can be directly met through the connection pool without re-connecting and authenticating the request to the database server. This saves time.
Disadvantages
There may be multiple unused connections in the database connection pool that have been connected to the database (this means a waste of resources ).
Tips
1. Create a connection pool only when you need a database connection, instead of creating a connection pool in advance. Once you use the connection, immediately close it. Do not wait until the Garbage Collector processes it.
2. Make sure that all user-defined transactions are closed before closing the database connection.
3. Do not close all connections in the database. at least ensure that one connection in the connection pool is available. If memory and other resources are your first concern, you can close all connections and create a connection pool when the next request arrives.
Connection Pool FAQ
1. When to create a connection pool?
When the first connection request arrives, a connection pool is created. The connection pool is determined by the connection character creation of the database connection. Each connection pool is related to a different connection string. When a new connection request arrives, if the connection string is the same as the string used by the connection pool, a connection is retrieved from the connection pool. If not, a new connection pool is created.
2. When will the connection pool be closed?
Close the connection pool when all connections in the connection pool are closed.
3. When all connections in the connection pool are used up and new connection requests arrive, what will happen?
When the connection pool reaches its maximum number of connections, new connection requests are placed in the connection queue. When a connection is released to the connection pool, the connection pool allocates the newly released connection to the connection requests queued in the queue. You can call close and dispose to return the connection to the connection pool.
4. How should I allow the connection pool?
For. NET applications, the connection pool is allowed by default. (This means that you don't have to do anything for it) Of course, if you can add pooling = true to the connection string of the sqlconnection object; make sure that your application allows the use of the connection pool.
5. How should I disable the connection pool?
By default, ADO. Net allows a database connection pool. If you want to disable the connection pool, you can use the following method:
1) when using the sqlconnection object, add the following content to the connection string: Pooling = false;
2) When using the oledbconnection object, add the following content to the connection string: ole db services =-4;
# Database Technology