In real life, programmers are naturally lazy. This fact keeps us stuck in bugs. Especially when ASP is used to process database connections, it will make you feel like you are in the oil pan.
In ASP, we establish a database connection and use ADO to obtain the data query results. The most commonly used is ADODB. connection and ADODB. recordset. let's take a simple example to learn how to use these two objects:
Dim objConn
Set objConn = Server. CreateObject ("ADODB. Connection ")
ObjConn. ConnectionString = "DSN = Northwind"
ObjConn. Open
Dim objRS
Set objRS = Server. CreateObject ("ADODB. Recordset ")
ObjRS. Open "SELECT * FROM Table1", objConn
If you are not familiar with database connection, read this article first.
(Http://www.4guysfromrolla.com/webtech/faq/Databases/faq2.shtml ).
We will discuss our theme from objRS. What will we do when we use objRS? Generally, programmers do not perform any operations. They ask ASP to take care of the background. when Server. when a CreateObject call occurs, the server allocates resources to operate on the new instances of these objects. If we do not explicitly notify the server that we no longer use these allocated resources, ASP should release these resources for us. full trust in ASP is a little risky. A safer and more credible way is to explicitly close and clear our Recordset and
The instance of the Connection object.
How can we close our objects and release the allocated memory? All we have to do is call the following four lines of code when we use these two objects:
ObjRS. Close
Set objRS = Nothing
ObjConn. Close
Set objConn = Nothing
This will force the release of resources, far better than relying on ASP to automatically release resources implicitly. Now, you may wonder: is this really important? Who will write four more lines of code on each ASP page connected to the database? The benefits of doing so far exceed the burden of writing four lines of code.
ActiveServerPages.com (http://www.activeserverpages.com/) some of the webmaster's words:
"You should disable Recordset, set it to Nothing, close Connection, and set it
Nothing. Standard resource fragment collection is incomplete and untrusted. [fragment collection mentioned above
Set. Charles refers to the implicit clearing of resources allocated by the server.]
"DataReturn [an ASP webhosting company] Many sites rely on IIS for automatic fragment collection with terrible errors. after several lines of code Close/Set Nothing are added, these sites run up as cheerfully as a horse. all major sites have rigid rules for explicitly releasing resources."
If Charles doesn't convince you yet, let's discuss a problem that arises because there is no explicit memory redistribution. This is a real example. brian Fairchild uses Access as the background database to support an ASP large site. he found that the ASP page will be completely stopped every time after a while! The HTML page is displayed normally, but all ASP pages are completely paralyzed and the system has to be restarted. finally, Brian found that, when the Recordset and Connection objects are explicitly closed and released, all faults would disappear. (look at the message board Brian talked about this fault) (http://www.aspmessageboard.com/forum/performance.asp?
M = 1321 & P = 1 & F = 23)
Charles Carroll also tells us that Access users should increase the default number of threads. Here is what Charles said:
"The default number of Access threads in the registry is 4. adding it to 20 will make the server run exceptionally smoothly, but it is only useful for Access. The CPU usage of our server is 100% from eight o'clock A.M., however, after I increase the number of threads, the CPU on the server will immediately cool down."
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