However, the new connection is created and placed inAdo. net connection pool, The application should beProgramYou can reuse this connection without having to implement the entire database connection creation process.Ado. net connection poolClose the connection pool when all connections in ....
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 ImplementAdo. net 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.
- Cainiao's detailed description of ADO. Net Access Technology
- How to load the ADO. Net Control
- Explore ADO. net
- Process description of collection ADO. Net Elements
- Add the ADO. NET Entity Data Model file ..
Advantages
The main advantage of using a connection pool is performance. Create a new databaseAdo. net connection poolThe time consumed 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.
Missing
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 have used the connection, close it immediately,Ado. net connection poolDo not wait for the garbage collector to process 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.
Ado. net connection poolFAQ
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 to closeAdo. net connection pool?
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 default value is allowAdo. net connection pool.