Understand and optimize Connection objects

zhaozj2021-02-16  49

In the ASP database programming, the Connection object is an object we cannot leave, and any operations are performed on the database, such as update record, insert, delete, retrieval, etc., must be done with the Connection object. In the image, the Connection object is the pipeline of the program to communicate with the database. All the operations of the database must pass it, so, no matter what kind of way we connect the database, you always do less the following code. Set conn = server.createObject ("adoDb.connection")

Create an instance variable of a Connection object, then create a RecorderSet object on it or a Command object to operate the database. Since the Connection object is 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.

Whenever a customer performs a database operation, you need to use a Connection object, while each Connection object will take up a part of the server, and the database's simultaneous connections cannot be unlimited, therefore. When we need to provide a high-performance database web program, we need to test how to reduce the server's cancellation. Generally speaking. A Connection object is created in each ASP page, which will generate a connection to the database in the server. The Connection object of different pages cannot be shared. Then. Can we share a Connection connection channel to different pages accessed by the same user.

Everyone wants to think about the SESSION object of the ASP six built-in object, he can save a private data for a particular user. If we save the Connection object in the session object, do you make different ASP pages Use the same connection channel? Take a look at this program below.

<%

Set conn = server.createObject ("adodb.connection") dbpath = server.mappath ("/") & "/ news / data / data.mdb" conn.open "Driver = {Microsoft Access Driver (* .mdb)} ; DBQ = "& dbpathsession (" conn ") = connSet RS = server.createObject (" adoDb.recordset ") SQL =" Select * from data "CN = session (" conn ") rsopen sql, cn, 3, 2

%>

In this database connection. We use the session object, first, create a CONN connection object, then connect to the database data.mdb, after obtaining the handle, save it in the session session variable in the session ("conn)), before opening the recordset The handle is taken out from the session ("conn") to with the session object. We can share different ASP pages to share a connection object, reducing the unnecessary of the server memory, and we don't need to worry, when a customer causing the server because the server cannot draw the occupied session connection object, because we know Each customer's session object is a certain survival period. After this period, the server will automatically discharge it.

转载请注明原文地址:https://www.9cbs.com/read-19118.html

New Post(0)