ASP to enable the database to read when the need to open the 1th/2 page _ Application Tips

Source: Internet
Author: User

Careful developers sometimes think of a page in which we need to read and write a database that contains similar
<!--#include file= "conn.asp"--> code, when you do not read the operation, the database is what kind of state?
So, is there any way we can get the database connection to open only when we need to read the database, without any action when we read it?

The idea is to encapsulate the database connection code in a function and call it when it needs to be read.

The following is the SQL connection code:

Function Open_conn ()
Dim conn,strconn
Set Conn=server.createobject ("Adodb.connection")
strconn = "Provider = SQLOLEDB; User ID = database login account; Password = database login password; Initial Catalog = database name; Data Source = (local);
Conn.Open strconn
Set Open_conn=conn
If ERR Then
Err. Clear
Conn.close:set conn=nothing
Response.Write "Sorry, there was an error in the database connection. "
Response.End
End If
End Function

Call Method:

will be the original

Rs.Open Sql,conn

Change into

Rs.Open Sql,open_conn ()

The following is the Access connection code:

Current 1/2 page 12 Next read the full text

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.