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