ASP Simple Database Connection class

Source: Internet
Author: User


Class cls_db
Private ConnStr
Private DBPATH,DBLINK,DBI
'==============================
' Function name: db_conn
' Function: Database connection function
Parameters
'==============================
Private Sub Db_conn ()
On Error Resume Next
Set Conn = Server.CreateObject ("Adodb.connection")
Connstr= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath (Sitedb)
Conn.Open ConnStr
If ERR Then
Call Asperr ()
End If
End Sub

'==============================
' Function name: Db_open
' function: Create a Read object
Parameters
'==============================
Public Sub Db_open ()
Call Db_conn ()
Set rs=server.createobject ("Adodb.recordset")
End Sub

'==============================
' Function name: db_close
' function: Close Read object
Parameters
'==============================
Public Sub Db_close ()
Set rs=nothing
If IsObject (Conn) Then Conn.close
Set Conn = Nothing
End Sub

'==============================
' Function name: Asperr
' Function: Connection error
Parameters
'==============================
Private Sub Asperr ()
Dblink = Request.ServerVariables ("url")
Dblink = Split (Dblink, "/")
For DBi = 0 to Ubound (dblink)-1
DBPath = Dbpath&dblink (DBi) & "/"
Next
Response.Write "<body style= ' font-size:12px ' >"
Response.Write "Error Number:" & Err.Number & "<br/>"
Response.Write "Error Description:" & Err.Description & "<br/>"
Response.Write "Source of Error:" & Err.Source & "<br/>"
Response.Write "</body>"
Err.Clear
Response.End
End Sub
End Class

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.