Use connection pool
Wang ran
Microsoft Certified lecturer
Wangran@itgoldenbridge.com
Click "add MSN robot"
Download the msdn Chinese network broadcast course for you!
This course includes
? Connection Pool
? Use a connection pool? Manage connection pools? Use transactions? Monitoring connection pool
Conditions required to listen to this course
? Familiar with basic ADO. net connections? Familiar with. NET database application development
Level 300
Concept of Connection Pool
? The connection pool is a process.
? This process saves the connection and makes it active.
Connections can be reused.
If no connection pool exists
? Connect to the data source
-Establish a physical channel (such as a socket or named pipe)-perform the first handshake with the server
Analyze connection string Information
-The server authenticates the connection.-Run the check to register the connection in the current transaction -...
Function of Connection Pool
? Through the database connection pool, applications can reuse the pool
Existing connection, instead of repeatedly establishing new connections with the database.
? Using the connection pool can significantly improve application scalability
Because a limited number of database connections can provide services for a large number of clients.
? At the same time, it can save the large size required to create new connections.
Using the connection pool can also improve performance. ? Transparent for Applications
Work Process
? When the pooling parameter is true (default), is the connection pool enabled? The two connected connection strings are placed in the same connection
Connection Pool
? The two connection strings are placed in different
Connection Pool in progress
? When the connection is closed, the connection is placed in the connection pool for reuse.
Use
? When the connection is dispose, the connection is permanently deleted.
? When the last connection in the connection pool is closed, the connection pool is deleted.
Control the SQL server connection pool
? Connection string variables related to the SQL server connection pool
? Connection lifetime connection lifetime
The default value is 0.
? Connection Reset
The default value is true.
? Enlist
Registration
The default value is true.
? Max pool size
Maximum pool size default value: 100
? Min pool size
Minimum pool size default value 0
? Pooling
Pool
The default value is true.
Control ole db connection pool
? The default connection pool function is activated and connected to ole db.
Used in connection
? To disable the ole db connection pool
Specify "ole db services =-4" in. The Code is as follows:
Dim cnnorthwind as new oledbconnection ()
Cnnorthwind. connectionstring =
"Provider = sqloledb;" & _ "Data Source = London;" & _ "Integrated Security = sspi;" & _ "ole db services =-4; "& _" Initial catalog = northwind ;"
Use connection pool
? The connection is based on the exact match algorithm on the connection string.
Pooled.
? The pool mechanism is even sensitive to spaces between name-value pairs.
Close connection
? After the connection is used up, will the connection be closed immediately? Do not close the connection in the Finalize method of the class.
-It is executed only when garbage collection is performed.
-The connection pool may be full.
? The connection explicitly opened before the dataadapter is not automatically closed.
Closed
Resident of the Connection Pool
? If minpoolsize is not specified in the connection string
Or if it is specified as zero, the connection in the pool will be closed after a period of inactivity.
? If the specified minpoolsize is greater than zero
The connection pool will not be damaged until the appdomain is detached and the process ends.
? Maintenance of inactive or empty pools only requires minimal system startup
Sales.
Clear connection pool
? Clearallpools
-Clear the connection pool of the given provider.
? Clearpool
-Clear the connection pool associated with a specific connection.
-If the connection is in use during the call, the corresponding tag is recorded. When the connection is closed, it will be discarded rather than returned to the pool.
Pool fragments
? Pool fragments are common in many web applications.
The application may create a large number of pools that will be released after the process exits. In this way, a large number of connections will be opened, occupying a lot of memory, thus affecting performance.
-Pool fragmentation caused by integration Security
-Because many databases generate pool fragments
Transaction support
? The connection is retrieved from the pool and allocated based on the transaction context.
-Unless enlist = false is specified in the connection string, the connection pool ensures connection.
Register in the current context.
-When the connection is closed through the registered system. Transactions transaction and returned to the pool
The connection will be retained so that the same connection can be returned the next time the same system. Transactions Event requests the connection pool (if the connection is available ).
-If the connection is unavailable, a new connection is opened.
-If no connection is available for the transaction, the connection is automatically registered when the connection is opened.
? When the connection is closed, it will be released back to the pool and based on its transaction Context
Add the corresponding sub-parts.
-Therefore, even if the distributed transaction is still suspended, the connection can still be closed without generating
Error.
-In this way, you can submit or stop distributed transactions later.
Dedicated transaction pool
? The connection pool is divided into multiple transaction proprietary pools and a pool corresponding to the connections that are not currently registered in the transaction. ? For threads associated with a specific transaction context, the connection is returned to the corresponding pool (the pool contains the connections registered in the transaction.
? This makes it transparent to use registered connections.
Process.
Use the pool object to manage the connection pool
? As a distributed developer, you are encouraged to disable the ole db resource pool and/or ODBC connection pool,
And use the COM + Object pool as the technology for pooled database connection.
? There are two main reasons:
-The pool size and threshold values can be clearly configured (in the COM + directory ). -Improved performance. The performance of the pool object method is 50% higher than that of the local pool.
? If you are using the ole db. NET data provider, you may need to consider using
COM + Object pool to make full use of excellent configurations and improve performance. If you develop a pool object for this purpose, you must disable the ole db resource pool and automatic transaction registration (for example, by adding "ole db services =-4" to the connection string "). You must process transaction registration in your own pool object implementation.
? For SQL Server. NET data providers, it uses the pool mechanism internally
So that you no longer need to develop your own object pool mechanism (when using this provider ). Therefore, you can avoid complex tasks associated with manual transaction registration.
Monitoring connection pool
? SQL Server event probe? Performance Monitor
? Programming Method
Review
? Connection Pool
? Use a connection pool? Manage connection pools? Use transactions? Monitoring connection pool
Get more msdn Resources
? Msdn Chinese website
Http://msdn2.microsoft.com/zh?cn? Msdn Chinese network broadcast
Http: // www.microsoft.com/china/msdn/webcast? Msdn Chinese network broadcast course advance email
Http://www.microsoft.com/china/msdn/WebcastNewsletter? Msdn free Chinese express mail (msdn flash)
Http://msdn2.microsoft.com/zh?cn/flash? Msdn Development Center
Http://msdn2.microsoft.com/zh?cn/developercenters
? Msdn Book Center
Http://www.microsoft.com/china/msdn/book
Question & answer
To raise a question, enter the text in this area and click the question button in the upper-right corner of question and answer.
You can also seek help at the Microsoft Chinese technology forum. lecturers of the msdn Chinese network broadcast regularly answer technical questions related to the course on the forum.
Http://forums.microsoft.com/china