Printer Friendly Version      Send     
Click to Rate and Give Feedback
Related Articles

Download Visual Round-trip Analyzer (VRTA) to uncover the root of your Web page loading problems and identify these 12 common ailments.

Jim Pierson

MSDN Magazine November 2008

...

Read more!

Ken Getz shows how the CollectionChanged event lets you reflect changes to your underlying data source In your bound data controls.

Ken Getz

MSDN Magazine December 2008

...

Read more!

Find out how to integrate SharePoint and Silverlight by creating a Silverlight media player and deploying it as a SharePoint Web Part.

Steve Fox and Paul Stubbs

MSDN Magazine November 2008

...

Read more!

Because Virtual Server is built upon a set of COM modules, you can creation and testing of virtual machines. Here we use Windows PowerShell to run the tests.

Dr. James McCaffrey and Paul Despe

MSDN Magazine December 2008

...

Read more!

Learn how to use Windows Presentation Foundation (WPF), XAML, and the deep XML support in Visual Basic to generate user interfaces dynamically.

Beth Massi

MSDN Magazine October 2008

...

Read more!

Also by this Author

Ken Spencer

MSDN Magazine September 2002

...

Read more!

Ken Spencer

MSDN Magazine September 2003

...

Read more!

In past versions of Visual Basic, there were rudimentary graphics controls. In Visual Basic .NET you have the GDI+ library, which enables you to draw lines, circles, and most anything else. But how can you use the functionality of GDI+ to create lines and other graphics that respond to user mouse clicks and events? Find out.

Ken Spencer

MSDN Magazine June 2003

...

Read more!

Ken Spencer

MSDN Magazine November 2002

...

Read more!

Ken Spencer

MSDN Magazine October 2002

...

Read more!

Popular Articles

Writing a Web application with ASP.NET is unbelievably easy. So many developers don't take the time to structure their applications for great performance. In this article, the author presents 10 tips for writing high-performance Web apps. The discussion is not limited to ASP.NET applications because they are just one subset of Web applications.

Rob Howard

MSDN Magazine January 2005

...

Read more!

C# allows developers to embed XML comments into their source files-a useful facility, especially when more than one programmer is working on the same code. The C# parser can expand these XML tags to provide additional information and export them to an external document for further processing. This article shows how to use XML comments and explains the relevant tags. The author demonstrates how to set up your project to export your XML comments into convenient documentation for the benefit of other developers. He also shows how to use comments ...

Read more!

Kenny Kerr sings the praises of the new Visual C++ 2008 Feature Pack, which brings modern conveniences to Visual C++.

Kenny Kerr

MSDN Magazine May 2008

...

Read more!

When incorporating the ASP.NET DataGrid control into your Web apps, common operations such as paging, sorting, editing, and deleting data require more effort than you might like to expend. But all that is about to change. The GridView control--the successor to the DataGrid-- extends the DataGrid's functionality it in a number of ways. First, it fully supports data source components and can automatically handle data operations, such as paging, sorting, and editing, as long as its bound data source object supports these capabilities. In addition, ...

Read more!

One-time passwords offer solutions to dictionary attacks, phishing, interception, and lots of other security breaches. Here's how it all works.

Dan Griffin

MSDN Magazine May 2008

...

Read more!

Our Blog

The basic security mechanism of Windows involves having a trusted system component check permissions and rights (AccessCheck) before an operation is allowed to proceed.

In the November 2008 issue of MSDN Magazine, John R. Michener explains how to set values for the security settings on objects and how those values are processed.

...

Read more!

It’s helpful to think about secure design from a more holistic perspective by using threat models to drive your security engineering process.

In the November 2008 issue of MSDN Magazine, Michael Howard proposes using the threat model to help drive other SDL security requirements, primarily code review priority, fuzz testing priority, ...

Read more!

Because Windows Workflow Foundation (WF) is based on a runtime that manages the execution of workflows and activities, testing must, in almost all cases, involve the use of the runtime – and this can introduce some interesting challenges.

In the November 2008 issue of MSDN Magazine, Matt Milner presents some techniques for unit testing ...

Read more!

Choosing the best alternative is a common task in software development and testing. A group of beta users may need to choose the best user interface from a set of prototypes. Or imagine the members of an open source project voting for a policy.

In the November 2008 issue of MSDN Magazine, Dr. James McCaffrey describes five of the ...

Read more!

Wouldn't it be nice to generate all your maintenance screens in your data-driven applications automatically?

In the October 2008 issue of MSDN Magazine, Beth Massi shows you how to create Windows Presentation Foundation (WPF) user interfaces at run time using Visual Basic XML Literals and XML namespace imports.

Read more!

This article may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. To maintain the flow of the article, we've left these URLs in the text, but disabled the links.
MIND

Compiling Components in Visual Basic for ASP

Ken Spencer

Code for this article: Serving0300.exe(32KB)

T
here are lots of little issues that come into play when you begin to design and build software around any set of technologies. After all, designers can't know how each developer will try to use their technologies in an application. That's one reason why you face so much trial and error when you build applications.
      In this column I'll give you some tips for buildingâ€"and more specifically, compilingâ€"components to be used with Microsoft® Transaction Server (MTS) and Internet Information Server (IIS), so that you can avoid some common pitfalls during your own development process.

ASP Components

      First, let's talk about what happens when you need to recompile a component that is being used in an ASP application. When you use a component from within your ASP code, you cannot delete, replace, or recompile the component until you do one of two things. If the ASP application is running in-process with IIS, you must shut down IIS before the file is modified. If the ASP application is running out-of-process, you can click the Unload button on the application's Directory Properties page. Once you have either stopped IIS or unloaded the application, you can delete, replace, or recompile the component.
      Each of these processes is a hassle because most people start the Internet Service Manager and use it for both tasks. There is an easier way to stop and restart IIS. You can perform both of these tasks from the Command Prompt using the Net command. I created two small command files that stop and restart IIS for me.
      When I need to stop IIS, I run the following command file:


IISStop.cmd
net stop iisadmin /yes
This stops the iisadmin service, which will in turn stop the other Web services. The iisadmin service must be stopped before you can replace a component that has been used in an ASP page.
      To restart IIS, I run this command file:


IISStart.cmd
net start iisadmin
net start w3svc
net start smtpsvc
This file restarts the iisadmin, w3svc, and smtpsvc services. You must restart each one explicitly because even though stopping iisadmin stops the others, restarting iisadmin will not restart the other services automatically.

MTS Components

      Now let's take a look at MTS and how it applies to your applications. I do most of my development on my workstation. When the component is ready for more extensive testing, I publish a copy of it on a server for testing. Developing on my workstation saves time because I can start and stop services without bothering anyone else on the network. I've also discovered an MTS add-inâ€"the Visual Basic® Transaction Server Add-inâ€"that lets you automatically refresh a component in an MTS package after the component has been recompiled. This is a big deal because now you don't need to delete and reinstall the component in MTS after you compile it. The add-in also allows you to refresh all of the components in a package.
      The MTS add-in is not installed by default when you install the Windows® NT Option Pack. To install it, start the Windows NT Option Pack setup. Click the Add/Remove button, then select Transaction Server from the list of components and click Show Components. Next, select Transaction Server Development and click Show Components once more. Finally, make sure the Visual Basic Transaction Server Add-in is selected, as shown in Figure 1. Once you have selected the add-in, click OK and finish the installation.
Figure 1 Installing the MTS Add-in
Figure 1 Installing the MTS Add-in

      Once you have the add-in installed, it will show up in the Visual Basic Add-Ins menu. The add-in is enabled by default and automatically set to refresh components, as shown in Figure 2. You can toggle this behavior on or off by selecting the first menu option.
Figure 2 AutoRefresh Components
Figure 2 AutoRefresh Components

      Now, for completeness, let's walk through the process of using a component with MTS. First, open your project in Visual Basic. Create a project reference to the Microsoft Transaction Server Type Library, then add in support for the MTS context object by adding the following code to the top of a procedure:



Dim Ctx As ObjectContext
Set Ctx = GetObjectContext
Now your component can interact with MTS as needed using SetComplete, SetAbort, or other MTS features.
      Before you go any further, open the properties for the project and click the Components tab. Make sure you set the compatibility property to either Project or Binary. You can usually use Project during your testing. If you do not set the compatibility property, you will run into problems when you recompile the component because a new GUID will be generated each time. This will prevent MTS from finding the newly compiled component and will lead to the following error when you try to use it:


Microsoft VBScript runtime error '800a01ad'
ActiveX component can't create object: 'MTSDB.Recordset'
/MIND/MTSDriver.asp, line 31
      If you get this error, you can take a look at what MTS is doing with Task Manager. If you sort the processes by image name, take a look at MTX.EXE. You should see one of these processes running whenever you are using IIS. If MTS tries to load a component and can't, you will see a new MTX.EXE for that package start and quickly disappear. Then the aforementioned runtime error will appear in the browser. Setting the compatibility property for the project as suggested will prevent this.
      Next, you can set the MTS transaction type for your classes. You can set the transaction type in either MTS Explorer or in Visual Basic. I prefer to set it in Visual Basic because this compiles it into the component and makes sure it is set correctly every time you install the component in MTS. To set the transaction type, select the class you are working with in the Visual Basic Project Explorer. Next, select the correct transaction type in the properties window. You can set the transaction type according to the table in Figure 3 (pulled from the MTS docs).
      Once you have set the transaction type, you can compile the component and install it in MTS. To do this, you will need an MTS package. To create a new package, start MTS Explorer and select the Packages Installed folder. Right-click Packages Installed and select New, then Package. Next, click "Create an empty package." Enter the package's name and click Next. If you are building a package on your workstation for testing, you can leave the security set at Interactive user and then click Finish.
      If this package will be used on a server, you should set the identity for the package to a valid account. I suggest that you create an account specifically for use by MTS and assign it the permissions and rights it needs. Then you can assign this account to the MTS package, as shown in Figure 4.
Figure 4 Setting the Package Identity
Figure 4 Setting the Package Identity

      You can enter the identity for a package either when you create it or when you use it later. To add the identity for the package later, open the properties for the package in MTS Explorer and select the Identity tab. You will need the password for the account that you assign to your package.
      Now you can install the component into MTS. Drag the component from Windows Explorer and drop it into the MTS packages Components folder. You can also install the component into a package by selecting New from the context menu of the package's Components folder, then following the prompts. If you have any problems installing a package by dragging and dropping, you can use the menus in MTS Explorer.
      Now that your package has been installed in MTS, you can execute an application that uses it and begin your testing. What happens with MTS when you need to recompile the component? Well, that's when it starts to get interesting. If the package is running as a Server package (meaning it runs in its own process space), you do not need to shut down IIS. You can simply shut down the package itself. Do this by opening MTS Explorer, right-clicking the package, and selecting shut down from the shortcut menu. This will kill the copy of MTX.EXE that is hosting the package, allowing you to recompile the component.
      Sometimes it will seem like you cannot recompile the component because something is holding it open. If you are using Visual InterDev® and have a page open that uses the component, you cannot recompile until you close the page. That's because Visual InterDev is holding a reference to the component and will not allow you to recompile until that reference is gone.

Automating MTS Package Shutdown

      It is cumbersome to continually shut down the MTS package to recompile a component. It's easier than shutting down IIS, but still requires flipping over to MTS Explorer and so forth. Luckily, the MTSAdmin object's interface allows you to automate this process. I hacked together some Visual Basic code that will allow you to shut down a package on your local system (see Figure 5 and Figure 6).
       Figure 5 shows the code for the application. If you run the app without any command-line parameters, frmMTSUTilInferface will display a list of MTS packages. Selecting a package will turn on the Shutdown Package button, as shown in Figure 7. Clicking this button will shut down the selected package.
Figure 7 Shutting Down a Package
Figure 7 Shutting Down a Package

      You can also execute the application with a parameter to shut down a package automatically. The shortcut looks like this:



MTSUtil.exe \Shutdown MindMTS
This command will shut down the MindMTS package. To work faster, you can create an icon on the taskbar for each of the packages that you are working on. Then you can simply edit the icon's properties and specify the associated package name as I did in the shortcut I just mentioned. Clicking that icon on the taskbar will then shut down the package.
      The code shown in Figure 6 does all the work using the MTS Admin object. To use these functions, you should create a project reference to the MTS 2.0 Admin Type Library when you're working on the code in Visual Basic.
      You can also compile Visual Basic-based applications and components from the command line. To compile from the command line, you supply Visual Basic with the following syntax:


"c:\program files\microsoft visual studio\vb98\vb6.exe"
/make MTSDB.vbp
This command launches Visual Basic from the command line with the /make parameter and compiles the MTSDB component. The entire command should be on one line, and you should remember to put quotes around the executable's long file name.
      To make compiling a simpler process, you could add functions to the MTSUtil.vbp app to automatically compile the components in a package after the package is shut down. You can use the Shell command in Visual Basic. Then all you need to do to recompile is save changes to the component and click the icon. That does all the work.

Conclusion

      As you can see from my discussion of building components for IIS and MTS, even the seemingly straightforward process of changing and recompiling a component can create unforeseen problems. But if you know about common compile time hassles beforehand, you'll save yourself lots of time and aggravation when building your components.

Ken Spencer works for the 32X Tech Corporation (http://www.32X.com), which specializes in conducting high-quality seminars on Microsoft technology. You can reach Ken at kenspencer@32x.com.

From the March 2000 issue of MSDN Magazine.

Page view tracker