Asp.net efficient database connection code analysis

Source: Internet
Author: User

This is a normal program. This program is placed on a page. No matter how many users or users simultaneously request this page, you can view it through sp_who after the request processing is complete, or that one. You know why it's called a normal program. It's in line with normal reasoning.

Using (sqldatareader reader = maticsoft.dbutility.dbhelpersql.exe cutereader ("select top 1 * from protuct order by id desc "))
{
While (reader. read ())
{
Response. write (reader ["name"]. tostring ());
}
}
Using (sqldatareader reader2 = maticsoft.dbutility.dbhelpersql.exe cutereader ("select top 1 * from users order by userid desc "))
{
While (reader2.read ())
{
Response. write (reader2 ["username"]. tostring ());
}
}

Let's take a look at the data connection code that some of our friends often use.

Data source = .; initial catalog = test; persist security info = true; user id = testuser; password = 123456; min pool size = 10; max pool size = 150; connection lifetime = 10

Min pool size = 10; max pool size = 150; connection lifetime = 10

The connection pool of the database tutorial is enabled by default. The above attribute is used to configure the connection pool. This means that when you send a database Request to your page, you do not have to create a database connection, but it may be from an existing connection pool, activate a connection to process your request. Similarly, when you call close in your code to explicitly close the database connection, it is not necessarily that the database connection is actually closed, if the current connection pool does not meet the min pool size requirement, it only returns to the connection pool and waits for the next command to activate it.


Sp_who 'testusers' // testusers is the user name you specified when establishing the connection

Check the number of connections.

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.