Use VB 6 to encapsulate ASP code and create DLL Components

Source: Internet
Author: User

This article is just an example, and users must use it flexibly according to their specific needs.
Example of recommending the blog ASP Component of csdn tornado. Net:
Http://blog.csdn.net/online/category/9939.aspx

Start VB6.0 and create the --> active DLL project. Click "project" --> reference and select "Microsoft Active Server Pages ".

Object Library"
And "Microsoft ActiveX Data Objects 2.1 library. Change the class module name to dcss. Change the project name.

Change to yygwy. Save the project file yygwy. VBP and class file dcss. Cls.
Write in dcss. CLS:
Private myscriptingcontext as scriptingcontext
Private myapplication as application
Private myrequest as request
Private myresponse as response
Private myserver as server
Private mysession as session

Public sub onstartpage (passedscriptingcontext as scriptingcontext)
Set myscriptingcontext = passedscriptingcontext
Set myapplication = myscriptingcontext. Application
Set myrequest = myscriptingcontext. Request
Set myresponse = myscriptingcontext. Response
Set myserver = myscriptingcontext. Server
Set mysession = myscriptingcontext. Session
End sub

Public sub onendpage ()
Set myscriptingcontext = nothing
Set myapplication = nothing
Set myrequest = nothing
Set myresponse = nothing
Set myserver = nothing
Set mysession = nothing
End sub

'The preceding statements are required.
'Define two public functions

Public Function rsresult (strsql as string) as recordset
Dim mycnn as connection
Dim myset as recordset
Dim strconnstring as string
'Strconnstring = "provider = sqloledb.1;
Password =; "&" User ID = sa; "&" Initial catalog = vlog; "&" Data Source = hpe60;
Connect timeout = 15"
Strconnstring = "driver = {SQL Server}; server = Yang; uid = sa; Pwd =;
Database = dcss"
'Mycnn. connectionstring = strconnstring
Mycnn. Open strconnstring
Myset. activeconnection = mycnn
Myset. Open strsql, mycnn, 3, adw.text
Set rsresult = myset
End Function

Public Function datasource () as Variant
Datasource = "driver = {SQL Server}; server = Yang; uid = sa; Pwd =; database = dcss"
End Function

Compile and generate the dcss. dll file. Register the regsvr32 path dcss. dll.
Use Visual InterDev to open the global. Asa file. Of course, you can also use it in other files.
Set dcss = server. Createobject ("yygwy. dcss ")
Oconn = dcss. datasource ()
Application ("strconn") = oconn

You can call the following on other pages:
Set objconn = server. Createobject ("ADODB. Connection ")
Objconn. open application ("strconn ")

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.