Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the problems related to ADO.NET connection pooling?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "what are the problems related to ADO.NET connection pooling". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

ADO.NET connection pooling is a mechanism provided by Data Provider that allows connections used by applications to be kept in the connection pool without having to complete the complete process of establishing / closing connections each time. To understand connection pooling, you must first understand the relationship of "physical connections" in the program.

The complete process of establishing a connection when Data Provider receives a connection request is to first establish a new connection in the connection pool (that is, a "logical connection"), and then establish a "physical connection" corresponding to the "logical connection". The establishment of a "logical connection" must be accompanied by a "physical connection".

The complete process for Data Provider to close a connection is to close the physical connection corresponding to the logical connection and then destroy the logical connection. Destroying the logical connection must be accompanied by closing the physical connection. SqlConnection.Open () requests a connection from Data Provider, and Data Provider does not necessarily need to complete the complete process of establishing a connection.

You may only need to take an available connection from the connection pool; SqlConnection.Close () is a request to close a connection, and Data Provider does not necessarily need to complete the complete process of closing the connection, but may just need to release the connection back to the connection pool.

Here is an example to illustrate. The examples in this article all use Console Application. We use the operating system's performance monitor to compare the number of "physical connections" to the database with or without connection pooling. Because the performance monitor collects data at least once every second, in order to observe the effect, both Open and Close in the code are Sleep for one second after connection.

SqlConnection con = new SqlConnection ("server =.; database = northwind;pooling = false;trusted_connection = true"); for (int I = 0 con.Open (); System.Threading.Thread.Sleep (1000);} catch (Exception e) {Console.WriteLine (e.Message);} finally {con.Close (); System.Threading.Thread.Sleep (1000);}

First, do not use ADO.NET connection pooling for testing. In the above program, pooing = false means that the connection pool is not used. The program uses the same connection string Open & Close for 10 connections, and uses the performance counter to observe the number of "physical connections" of SQL Server.

As can be seen from the sawtooth below, each time con.Open () is executed, the number of ADO.NET connection pools for SQLServer increases by one, while the number of physical connections for SQLServer decreases with each execution of con.Close (). Because connection pooling is not used, Data Provider needs to destroy "logical connection" and "physical connection" every time Close connects, and Data Provider needs to establish "logical connection" and "physical connection" every time Open connection.

This is the end of the content of "what are the issues related to ADO.NET connection pooling"? thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report