Code for connecting to the database in the COM component in ASP

Source: Internet
Author: User

VB-project-reference-ADO 2.0, create a class dB, and set the project name to sqlconn
Below are even Program Part in Code If you are free, try again.
Option explicit
Public strerror as string
Public conn as new ADODB. Connection
Public RS as new ADODB. recordset

Public property get errorstring () as string
Errorstring = strerror
End Property

Public Function conn_open (strsqlservername, strsqldbusername, strsqldbpassword, strsqldbname)
Dim strcon as string
Set conn = new ADODB. Connection
On Error goto errhandler:
Strcon = "provider = sqloledb; server =" & strsqlservername & "; user id =" & strsqldbusername & "; Password =" & strsqldbpassword & "; database =" & strsqldbname &";"
Conn. Open strcon
Errhandler:
Strerror = "Error Source:" & err. Source & vbcrlf & "Description:" & err. Description
Exit Function
End Function

Function getrootid (byval classid)
Dim Query
Query = "select class_id, rootid from tblcategory where class_id = '" & classid &"'"
Set rs = conn. Execute (query)
If not (Rs. EOF and Rs. bof) then
Getrootid = RS ("rootid ")
Else
Getrootid = classid
End if
Rs. Close
Set rs = nothing
End Function

After compilation, it is used in ASP

function getrootid (byval ID) 'obtains the root class ID.
set s_db = server. createobject ("sqlconn. DB ")
s_db.conn_open strsqlservername, strsqldbusername, strsqldbpassword, strsqldbname
getrootid = s_db.getrootid (ID)
set s_db = nothing
end function

Related Article

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.