Use ADO. Net to access sqlserver pay attention to the size setting of the Connection Pool

Source: Internet
Author: User

In Visual Studio 2005, a tree-structured classification table is developed with Treeview. The data is stored in the database and called using recursive functions. The result is incorrect, after checking the database connection string, you have no intention to set the size of the Connection Pool minpoolsize = 4 maxpoolsize = 4. This setting causes recursive connection to access the database four times and an error occurs.

In addition, you must learn to use the using statement to release resources, which can reduce the number of connection pools.

The following explanation is found in the msdn document:

Connecting to the database server usually consists of several steps that take a long time. A physical channel (such as a socket or named pipe) must be established, and a handshake must be performed with the server for the first time. The connection string information must be analyzed and the server must authenticate the connection, check must be run to register in the current transaction, and so on. In fact, most applications only use one or several different connection configurations. This means that many identical connections will be opened and closed repeatedly during application execution. To minimize the cost of opening a connection, ADO. NET is calledConnection Pool.

The connection pool reduces the number of times new connections need to be opened.Pool ProcessMaintain the ownership of the physical connection. Manage connections by retaining a set of active connections for each given connection configuration. As long as the user calls open on the connection, the pool process checks whether there are available connections in the pool. If a pool connection is available, the connection is returned to the caller instead of opening a new connection. When an application calls close on the connection, the pool process returns the connection to the active connection pool instead of closing the connection. After the connection is returned to the pool, it can be reused in the next open call.

You can establish a pool connection only when the same connection is configured. Ado. Net retains multiple pools at the same time, and each pool is configured with one. Connections are divided into multiple pools by connection strings and Windows Identifiers (when using integrated security. Pool connections can greatly improve application performance and scalability. By default, the connection pool is enabled in ADO. net. Unless explicitly disabled, the pool process will optimize the connection when the connection is opened or closed in the application. You can also provide several connection string modifiers to control connection pool behavior.

The connection pool is created for each unique connection string. After a pool is created, multiple connection objects are created and added to the pool to meet the minimum pool size requirements. The connection is added to the pool as needed, but cannot exceed the specified maximum pool size (default value: 100 ). The connection is released back to the pool when it is closed or disconnected.

If an available connection exists when you request a SqlConnection object, the object is obtained from the pool. The connection must be available, not used, have a matched transaction context or not associated with any transaction context, and have a valid link with the server.

The connection pool process re-allocates connections when the connection is released back to the pool to meet these connection requests. If the maximum pool size is reached and no available connections exist, the request will be queued. Then, the pool process tries to re-establish any connection until the timeout time is reached (the default value is 15 seconds ). If the pool process cannot meet the request before the connection times out, an exception is thrown.

 

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.