ASP connects to the database by calling the DLL object method.

Source: Internet
Author: User

ASPCodeAs follows:
<%
Function getrootid (classid)
Dbpath = server. mappath ("database. mdb ")
Set s_db = server. Createobject ("sqlconn. DB ")
S_db.conn_open dbpath
Response. Write ("<br> the database is successfully opened! ")
Getrootid = s_db.getrootid (classid)
Set s_db = nothing
End Function
Classid = 22
Response. Write ("<br> query classid:" & classid)
Rsrootid = getrootid (classid)
Response. Write ("<br> root directory rootid:" & rsrootid)
%>

Create an ActiveX-DLL project in VB6.0
Point project-reference-Microsoft ActiveX Data Objects 2.8 Library
Project name sqlconn
Class Name DB
The sqlconn. DLL Code is as follows:

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 (dbpath)
Dim strcon as string
Set conn = new ADODB. Connection
On Error goto errhandler:
Strcon = "DBQ =" & dbpath & "; driver = {Microsoft Access Driver (*. mdb )};"
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 classid, rootid from articleclass where classid =" & 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 sqlconn. dll is generated, run the following command in the Start Menu: Enter regsrv32 D:/dll/sqlconn. DLL to store the registration path.
Test the ASP file in IIS.

Reference Web site http://www.jaron.cn/chs_scripts/8/2003-05/20030508152020-100943.html

database table in the Program . The connection method is not completely collected, but a common connection is called.
related database name: database. MDB
data table name: articleclass
Table Record: classid (22), rootid (4)
For details, refer to the manual database.

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.