The following are SQL connections:
Code :
Copy code The Code is as follows: function open_conn ()
Dim Conn, strconn
Set conn = server. Createobject ("ADODB. Connection ")
Strconn = "provider = sqloledb; user id = database Logon account; Password = database logon 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, database connection error. "
Response. End
End if
End Function
Call method:
Change the originalCopy codeThe Code is as follows: Rs. Open SQL, Conn
ChangeCopy codeThe Code is as follows: Rs. Open SQL, open_conn ()
The following is the access connection code:Copy codeThe Code is as follows: function open_conn ()
Dim dbpath, Conn
Dbpath = server. mappath ("database path ")
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open "Data Source =" & dbpath & "; provider = Microsoft. Jet. oledb.4.0 ;"
Set open_conn = Conn
If err then
Err. Clear
Conn. Close: Set conn = nothing
Response. Write "sorry, database connection error. "
Response. End
End if
End Function
Call method:
Change the originalCopy codeThe Code is as follows: Rs. Open SQL, Conn
ChangeCopy codeThe Code is as follows: Rs. Open SQL, open_conn ()