ASP Simple Database Connection class

Source: Internet
Author: User

Class cls_db
 private connstr
 private dbpath,dblink,dbi
 ============================ = =
  Function name: Db_conn
  for     use: Database connection function
  parameter     number:
 ======== ======================
 private Sub db_conn ()
  on Error Resume Next
  Set Conn = server.create Object ("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
  for     use: Creating Read objects
  parameters     Number:
 ==============================
 public Sub db_open ()
  Call Db_conn (
  Set rs=server.createobject ("Adodb.recordset")
 end Sub
 
 =================== ===========
  Function name: Db_close
  for     use: Turn off the Read object
  parameter     number:
 ==============================
 public Sub db_close ()
  Set rs=nothing
  If IsObject ( Conn) Then conn.close
  Set Conn = Nothing
 end Sub
 
 =============================< br>   Function Name: Asperr
   for     use: Connection error
  parameter     number:
 ========= ====================
 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.W Rite "error Description:" & Err.Description & <br/> "
  Response.Write" error Source: "& Err.Source &" <BR/ > "
  Response.Write" </body> "
  err.clear
  response.end
 end Sub
End Cl

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.