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 is the use of ADO.NET connection pooling

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "what is the use of ADO.NET connection pool". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what's the use of ADO.NET connection pooling?"

ADO.NET after a long period of development, many users are very familiar with ADO.NET, here I would like to publish a personal understanding, and discuss with you. Database connection, for the application system with database as the cornerstone of data storage, database connection is one of the most precious resources in the whole system. Database connection pooling is the most important measure to make more effective use of database connections. It is very important for the performance of a large application system, especially for Web applications. ADO.NET Data Provider (hereinafter referred to as Data Provider) will help us manage connection pooling, so some people say that using connection pooling is as easy as swimming in children's pools. But this is not to say that everything is safe with Data Provider programmers. Incorrect use of ADO.NET connection pooling may cause your application to drown in the pool. The author hopes that through this article, readers can thoroughly understand the importance of connection pool and correctly configure the parameters of connection pool according to the actual situation, understand the abnormal situations such as connection leakage and "dead connection" in practical application, and how to deal with them, so that the application can easily swim the connection pool.

What is ADO.NET connection Pool

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 between SqlConnection.Open (), SqlConnection.Close (), and opening / closing a "physical connection" 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. Data Provider does not necessarily need to complete the complete process of establishing a connection, but may only need to remove an available connection from the connection pool; SqlConnection.Close () requests 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) }} at this point, I believe you have a deeper understanding of "what is the use of ADO.NET connection pooling"? you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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