asp.net Efficient database Connection code analysis

Source: Internet
Author: User

This is a normal program, this program is placed in a page, no matter how you brush or how many people at the same time request the page, pending the processing of the end, through the sp_who check to see, or that one. You know why this is called a normal procedure, it fits the normal reasoning.

using (SqlDataReader reader = Maticsoft.dbutility.dbhelpersql.executereader ("SELECT top 1 * out protuct ORDER BY id DESC" ))
{
while (Reader.read ())
{
Response.Write (reader["name"].tostring ());
}
}
using (SqlDataReader reader2 = Maticsoft.dbutility.dbhelpersql.executereader ("SELECT top 1 * from users ' ORDER by UserID de SC "))
{
while (Reader2.read ())
{
Response.Write (reader2["username"].tostring ());
}
}

Take a look at the connection data code that some of our friends will use frequently.

Data source=.; Catalog=test;persist Security info=true;user id=testuser;password=123456;min pool Size=10;max pool size=150 initial; Connection lifetime=10

Min Pool Size=10;max Pool size=150;connection lifetime=10

Database tutorial Connection pool, the default is enabled, the above properties is to configure this connection pool. This also means that when your page sends a database request, it is not necessarily necessary to create a database connection, but it is possible to activate a connection from an existing connection pool to process your request; Similarly, when you call close explicitly closes the database connection in your code, it is not necessarily true to close the database connection. , if the current connection pool does not have a connection that meets the min pool size requirement, it simply 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 you established the connection

Look at the number of connections, now you see.

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.