Create a compilation component for your ASP program (on)

Source: Internet
Author: User

Compile custom Active Server Page (ASP) code to complete some tasks. For example, the database access capability is important. however, the most obvious problem with a scripting solution is performance. in this article, I will show you how to convert the script version of a database object into a dynamic link library (DLL), or just like its common name, a com component. to generate this compilation version, I will use Visual Basic 6 Service Pack 4. I once showed you how to create a VBScript object to simplify access to the data source. because this object may be used in large quantities, it is an ideal code that can be edited as a COM component at one end.

Visual Basic is a good development environment for creating COM components, and the compiler has become very efficient in version 6.0. in many cases, it can generate code as fast as C ++. this does not mean that you should not use C ++. often, some projects require an efficient component that can only be generated by C ++. however, because of the development speed and ease of use, most projects I participate in prefer Visual Basic. of course, your choice of development language is purely a matter of personal interests, so I will leave the question of language selection to you.

To recall the previous content, list A displays the VBScript version of the database object in the previous article.

It is not difficult to convert the script into a visual basic component. the first step is to start Visual Basic. the screen displayed after startup (unless you have asked Visual Basic not to display it) is the new project dialog box shown in. note that there is an ActiveX dll option. you only need to select this option and click the new button to generate a new visual basic project with all attributes set to create a com DLL. it automatically generates a new class named Class 1.

Click the project menu and select project 1 properties to open the dialog box shown in B. here, you can change the project name or set the option that determines how the component is compiled. name the project dbutil and select the "run independently" check box ". this option tells Visual Basic that the component does not have any user interaction process. this basically means that all the error messages and outputs will be output to the event records. set all other settings to the default value and click OK.

Start your class
Now that you have a COM component that can be run, it is time to get it involved. this component can be used in ASP for several steps. step 1: Modify pagedeclare in the framework. ASP file to reference the compiled component (List D) with an object tag ).

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 ults
Gexpirepage = true
Gpagetitle = ""
Gheaderinclude = ""
Gbodytaginclude = ""
%>

Object tagging is great because, unlike VBScript objects, DLL is not initialized before being used. after this, if your page uses a framework but does not require a dbconnect object, it will not introduce any additional actions. note that object tagging indicates that the object should be run on the server. this is required so that this tag will not run to the browser and attempt to create this object on the client.

The last thing to make this component work is to register it in the registry of your computer. the best way is to use Microsoft Transaction Server (MTS), which is actually the COM +. open the control panel and select administrative tools. in the management tool, double-click the Component Service icon. use the left-side Navigation Pane to browse "component services | computers | my computers | COM + Applications ". click "COM + application icon" and Right-click the icon above. select "New | application" from the pop-up menu ". create an empty application as prompted. then, name the application with any name you like and make sure that the "server application" option is selected. if our components need to access ASP objects, such as application and session, select "library application" for this option )". but for database access, "server application" is a better option.

For "application identity", you can select "Interactive User" as long as you log on to a development machine and use IIS )". if this is a server without logon, You need to declare a user account. therefore, you need to create a Security Authentication account that can be used by applications and components. this is a complex configuration process for a server that manages one or more domains. Therefore, it is best to use the "Interactive User" option for this test process.

Now, you should be able to browse your new program on the left panel and click the component folder of your application. to register your component, open an Explorer window and drag the DLL to the Panel on the right of the component service window. the name is dbutil. the dbconnection icon is displayed, as shown in E.

As long as you remove the musiclist line "set dbconnect = nothing. ASP files are ready to run. this call has expired because the object has been managed by MTS. once you delete the row, musiclist. ASP will be shown as before.

Summary
I hope this article will show you how easy it is to convert a VBScript object into a visual basic compiled DLL and use it on your ASP page. if we delete the "set dbconnect = nothing" sentence from the page, you only need to modify pagedeclare to convert the VBScript object to DLL. ASP file.

The compiled component still lacks proper error handling code. now that it is a visual basic object, you can use the on error goto method to capture any errors in the function. once an error is captured, you can either report the error or record it in the event log. in future sections, we will explore how to compile a session object and use regular expressions to verify data.

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.