Make a compilation component for your ASP program (bottom)

Source: Internet
Author: User
Get your class to work
Now that you have a COM component that you can run, it's time to get it to work. There are a few steps you can take to make this component available in ASP. Step one, modify the frame (framework) The pagedeclare.asp file in is used to refer to this newly compiled component (list D) with an object label.

Listing D
<%@ language= "VBScript"%>
<object runat= "Server" progid= "dbutil.dbconnection" id= "Dbconnect" ></object>
<%
Option Explicit

' <!--#include virtual= '/includes/classes/dbaccess.asp '-->

Dim gexpirepage
Dim gpagetitle
Dim gheaderinclude
Dim gbodytaginclude

' Dim dbconnect

' Set dbconnect = new DbConnection

' Set defaults
Gexpirepage = True
Gpagetitle = ""
Gheaderinclude = ""
Gbodytaginclude = ""
%>

Object subscript is great because unlike VBScript objects, DLLs are not initialized until they are used. After doing so, if your page uses frames but does not need dbconnect objects, It will not introduce any extra action. Note that the object specifies that the objects should run on the server. This is necessary so that the tab does not run to the browser side and then attempt to create the object on the client.

The last thing to make this component work is to register it in your computer's registry. The best approach is to use Microsoft Transaction Server (MTS), which is actually COM + on the Windows 2000 machine. Open the Control Panel and select the Management tool. In the Administration tool, double-click the Component Services icon. Browse the Component Services | computer | My Computer |com+ application using the left panel. Click the COM + application icon and then right-click on it. Select New | Application from the pop-up menu. Follow the prompts to create an empty application. Then, name the application with whatever you like, and make sure that the server application (application) is selected. If our component needs to access ASP objects, such as application and session, then this option should be selected "Library application Application". But for database access, the server application is a better option.

For application flag (application Identity), you can select Interactive User (Interactive users) as long as you are on a development machine and are logged on with IIS. If this is a server where no one is logged on, You will need to declare a user account. So you need to create a security authentication account that the application and components can use. This is a complex configuration process for a server that manages one or more domains, so it's best if you can use the "Interactive user" option for this test process.

Now, you should be able to browse your new program in the left pane and click on the component folder for your application. To register your component, Just open one of the Explorer windows and drag the DLL to the right pane of the Component Services window. An icon with a name of Dbutil.dbconnection will appear, as shown in Figure E.


Figure E

As soon as you remove the "set dbconnect=nothing" line musiclist.asp file is ready to run. This call has been invalidated because the object is already managed by MTS. Once you delete that line, musiclist.asp will show it like before. .

Summarize
I hope this article shows you how easy it is to convert a VBScript object to a Visual Basic compiled DLL and use it on your ASP page. If we delete the phrase "set dbconnect = Nothing" from the page, Converting from a VBScript object to a DLL requires only modifying the pagedeclare.asp file.

The compiled component also lacks the appropriate error-handling code. Now that it is a Visual Basic object, you can use on Error Goto to catch any errors that occur in the function. Once you've caught a mistake, you can either report the error, Or you can record it in the event log. In future sections, we'll explore how to write a Session object and validate the data with regular expressions.


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.