ASP Basics Tutorial (Next)

Source: Internet
Author: User
Tags command line end modify
Basic Tutorials | Basic Tutorials Iv. Development and use of ASP components:

1. Features of the component?

L Advantages:
n easy to invoke, save code
N High Security
n supports transaction processing, multi-component syndication
N Run Fast
n Upgrade, modify components without modifying the page, so scalability is good
L Disadvantages:
n Development and debugging difficulties

2. How to use VB development?

⑴. Open Vb>>new Project>>activex DLL

⑵. Modify project name to course


⑶. Modify the name of the class module conn_db


⑷. Project>> References, referencing the COM + Service Type Library and Microsoft Active Server Pages Object Library.

⑸. Modify the class code as follows:

' Establish a database connection and output database fields
Dim Response as Response
Dim Request as Request
Dim Server as Server
Dim Application as Application
Dim Session as session

Private Sub Class_Initialize ()
Dim Objcontext as ObjectContext
Set objcontext = GetObjectContext ()
Set Response = objcontext ("Response")
Set Request = objcontext ("request")
Set Server = objcontext ("server")
Set application = objcontext ("Application")
Set session = Objcontext ("session")
End Sub

Sub conn_db ()
Set conn = CreateObject ("Adodb.connection")
Conn.Open "Course_dsn", "Course_user", "Course_password"
Set rs = CreateObject ("Adodb.recordset")
Rs.Open "SELECT * from User_info", Conn, 1, 1

If rs.recordcount > 0 Then
For i = 1 to Rs.recordcount
Response.Write "<br>" & RS ("user_name") & "<br>"
If Rs. EOF Then Exit for
Rs.movenext
Next
End If
Rs. Close
Set rs = Nothing
Conn. Close
Set conn = Nothing
End Sub

⑹. Add a new class Cutstr

⑺. Modify the class code as follows:

' Intercept string
Function cutstr (str, length)
If Len (str) > Length Then
Cutstr = Left (str, length) & "..."
Else
CUTSTR = str
End If
End Function

⑻. File>>save

⑼. File>>make Course.dll

3. Registration components: MTS and Regsvr32.exe

There are two ways to register components: MTS and the use of Regsvr32.exe. MTS is worth recommending because it has the following advantages:
n Dynamic offload balancing to improve the upgrade of components and component-based applications.
n contains the ability to advertise and submit events and queue components, making it easier to combine with multiple components.

For a component to have an MTS feature, you must make minor changes to the component. When you develop under NT and 98, you must refer to the Microsoft Transaction Server type library in your project, developed under Windows 2000, and you must reference the COM + Service type library.

⑴. REGSVR32 registration:

Regsvr32.exe is an executable file under System32 that reads the component information into the registry so that ASP can invoke it.
Use the command line to enter the directory where the component DLL file is located, and execute "regsvr32 dll_file_name".


When you run Regedit, the course.conn_db and course.cutstr items are found under HKEY_CLASSES_ROOT, indicating that the component was registered successfully.


⑵. Register with MTS:

①. Start >> program >> management tools >> Component Services

②. Expand the directory to the following states:


③. Follow the wizard and next, until the following dialog box, click "Create an Empty Application":


④. In the next dialog box, name the Application "course", and the other defaults until complete

⑤. Expand the course application, right-click, and create a new component


⑥. Follow the prompts, continue, and select "Import registered Components" when the following dialog box appears


⑦. Select the component we developed, and the next step is to complete


⑧. At this point, you can see that there are two more components in the course application:


4. Calling Components in ASP

Asp_use_com.asp
<%
' ASP calls COM components
Set Cutstr_obj=server.createobject ("Course.cutstr")
Response.Write Cutstr_obj.cutstr ("Abcdefghijk", 3) & "<br>"
Set cutstr_obj=nothing

Set Conn_obj=server.createobject ("course.conn_db")
conn_obj.conn_db ()
Set conn_obj=nothing
%>

Effect:
Abc...

Ahyi

Tuth

Description the call succeeded.

5. Uninstalling components

⑴. Using regsvr32 registered components, use the-u switch to uninstall:


Note: First enter the directory where the component DLL resides, then uninstall using "Regsvr32–u Dll_file_name", and restart IIS after uninstalling.

⑵. Components registered with MTS, first remove the corresponding application in Component Services, and then perform step ⑴ to completely uninstall the component.


6. DLL component storage location and permission settings

⑴. All we need to do is copy the compiled DLL file and the other files don't have to be processed.

[1] [2] [3] [4] [5] Next page



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.