NET Platform Connection pool

Source: Internet
Author: User

Http://www.cnblogs.com/visionwang/archive/2012/11/16/2774203.html

NET Platform Overview of connection pooling

Ado. NET has provided us with such a connection pool management, each connection string produces a connection pool, sets the maximum number of connections to the pool, although you use Close or Dispose on dbconnection, the connection is not closed, in fact, is returned to the pool, the pool to manage these connections, Wait for the next request. The connection pool is freed from memory unless the connections in the connection pool are all closed. Multiple connection strings, resulting in multiple connections to the pool.

How do I implement a connection pool?

Make sure you use the same connection string (the same as the connection pool) for each connection, and only the connection string will work when the connection pool is connected. If the connection string is not the same, the application does not use a connection pool but creates a new connection.

Advantages

The main advantage of using connection pooling is performance. The time it takes to create a new database connection depends largely on the speed of the network and the distance between the application and the database server (network), and this process is often a time-consuming process. With a database connection pool, the database connection request can be met directly through the connection pool without having to reconnect to the request and authenticate to the database server, saving time.

Disadvantages

There may be multiple connections in the database connection pool that are not being used to connect to the database (which means a waste of resources).

Tips and Hints

1. When you need a database connection, create a connection pool instead of building it in advance. Once you're done using the connection, close it immediately, and don't wait for the garbage collector to handle it.

2. Ensure that all user-defined transactions are closed before closing the database connection.

3. Do not close all connections in the database, at least one connection in the connection pool is guaranteed to be available. If memory and other resources are issues that you must first consider, you can close all connections and then create a connection pool when the next request arrives.

Connection Pooling FAQ

1. When do I create a connection pool?

Creates a connection pool when the first connection request arrives, and the connection pool's establishment is determined by the connection word Fu Shilai of the database connection. Each connection pool is associated with 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 taken from the connection pool, and if it is not the same, a new connection pool is created.

2. when do I close the connection pool?

Closes the connection pool when all connections in the connection pool have been closed.

3. what happens when a connection in the connection pool is exhausted and a new connection request arrives?

When a connection pool has reached its maximum number of connections, new connection requests are placed in the connection queue when a new connection request arrives. When a connection is released to the connection pool, the connection pool assigns the newly freed connection to the connection request that is queued in the queue. You can call close and Dispose to return the connection to the connection pool.

4. How should I allow connection pooling?

For. NET applications, the default is to allow connection pooling. (which means you don't have to do anything for this matter) of course, if you can add Pooling=true to the SqlConnection object's connection string, make sure your application allows connection pooling.

5. How do I disable connection pooling?

Ado. NET defaults to allow database connection pooling, if you want to disallow connection pooling, you can use the following methods:

1) When using the SqlConnection object, add the following to the connection string: Pooling=false;

2) When using the OleDbConnection object, add the following to the connection string: OLE DB services=-4;

NET Platform Connection pool

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.