Analysis on ASP. NET database connection pool settings

Source: Internet
Author: User

For the ASP. NET database connection pool, you can use a group of name-value pairs to configure the connection pool as a link string. For example, you can configure whether the pool is valid and the default value is valid). The maximum and minimum capacity of the pool is used for the time when the queued requests that open the link are blocked. The following example string configures the maximum and minimum capacity of the pool.

"Server = (local); Integrated Security = SSPI; Database = Northwind;
Max Pool Size = 75; Min Pool Size = 5"

Summary of ASP. NET database connection pool

The connection pool allows applications to obtain 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 ASP. NET database connection pool

Make sure that each connection uses the same connection string 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 of ASP. NET database connection pool

The main advantage of using a connection pool is performance. The time required to create a new database connection depends on the speed of the network and the distance between the application and the database server. 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 of ASP. NET database connection pool

There may be multiple unused connections in the database connection pool that have been connected to the database, which means resources are wasted ).

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.

ASP. NET database 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 you don't have to do anything for this.) Of course, if you can add Pooling = true to the connection string of the SQLConnection object, make sure that your application allows the connection pool to be used.

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;

The basic information of ASP. NET database connection pool settings and operations will be introduced here, and I hope to help you.

  1. ASP. NET Overview
  2. Analysis on the advantages of ASP. NET in eleven aspects
  3. Analysis on ASP. NET database connection
  4. Configuration Analysis of ASP. NET database connection in web Applications
  5. Analysis of ASP. NET database connection instances

Related Article

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.