Understanding and Optimizing Connection objects

Source: Internet
Author: User
Tags connection pooling sessions server memory

In this database connection. We used the session object, first, to create a Conn connection object, and then connect to the database Data.mdb, get the connection handle, save it in the sessions ("conn") this conversation variable, before opening the recordset, from the "Conn") to remove the handle from the session object. We can make different ASP pages share a connection object, reduce the cost of server memory, and we do not need to worry about, when a customer because of the wrong operation caused the server can not extract the occupied session connection object, Because we know that each client's session object has a certain lifetime, after this deadline, the server will automatically analyze it out.

In ASP's database programming, the connection object is an object that we can not leave, in any operation to the database, such as updating records, inserting, deleting, retrieving and so on, must use the connection object to complete. Figuratively speaking, the connection object is the pipeline that the program communicates to the database, all operations on the database must pass through it, therefore, no matter how we connect to the database, we always have to execute the following code.

Set conn = Server.CreateObject ("ADODB. Connection ")

Create an instance variable of a Connection object, and then build the Recorderset object or Command object on it to manipulate the database. Since the connection object is so important, how to optimize and manage the connection object is extremely important to the database program, it is related to the performance of the program.

Every time a customer performs a database operation, a connection object is needed, and each connection object consumes a portion of the server's resources, while the number of concurrent connections to the database cannot be unlimited, so. When filtering to provide High-performance database Web programs, we need to test how to reduce the cost of the server. Generally speaking. Creating a Connection object in each ASP page creates a connection to the database in the server. The connection objects of different pages are not shared. So. Can we share a connection connection channel with the different pages that the same user accesses?

You may wish to think of our ASP six building object Session object, he can for a specific user to save private data, if we put the connection object in the Session object, can we make different ASP pages use the same connection channel? Take a look at this procedure below.

$#@60;%
Set conn = Server.CreateObject("ADODB.Connection")
DBPath = Server.MapPath("/")&"/news/data/data.mdb"
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
session("conn")=conn
Set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from data"
cn=session("conn")
rs.open sql,cn,3,2
%$#@62;
d width="100%">

In this database connection. We used the session object, first, to create a Conn connection object, and then connect to the database Data.mdb, get the connection handle, save it in the sessions ("conn") this conversation variable, before opening the recordset, from the "Conn") to remove the handle from the session object. We can make different ASP pages share a connection object, reduce the cost of server memory, and we do not need to worry about, when a customer because of the wrong operation caused the server can not extract the occupied session connection object, Because we know that each client's session object has a certain lifetime, after this deadline, the server will automatically analyze it out.

And the ODBC3.0 provides the connection pool connection pooling. can also effectively improve the performance of the database. We know that the connection objects generated in many ASP pages are always connected, disconnected, and disconnected.

How to effectively manage and use these abandoned connections, can also be a certain program to greatly improve the efficiency of the operation. ODBC3.0, however, provides the ability to intelligently redirect the new connection to the connection object that is about to be discarded, and to use it repeatedly. In this way, you can save the cost of the server.

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.