Debugging SQL Workflow Applications with Microsoft Script Editor

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

 

Amit Chopra, Brent Williams
Microsoft Corporation

March 2001

Applies to:
   Microsoft® Office XP Developer

Summary: This article describes how developers of SQL Workflow applications can use the Microsoft Script Debugger included with Microsoft Office XP to enhance the debugging functionality of Workflow Services for SQL Server. (4 printed pages)

Contents

Introduction
Installing the Required Software
Debugging a Workflow Application
Attaching to Code That Is Already Executing

Introduction

The ability to quickly deploy a solution is largely dependent on how quickly a developer can debug the code when required. The Microsoft Office XP Developer does not have an integrated debugger; however, you can use the Just-In-Time Debugging process to debug the Microsoft® Visual Basic® Scripting Edition (VBScript) used on event scripts.

There are certain limitations to the process described in this article, such as having to debug on the same machine as the Workflow Services are installed, and switch back to the Microsoft Office XP Development Environment to make changes to the code. Despite these limitations, you will find it extremely useful to enhance your debugging experience with the SQL Workflow event scripts and efficiently deploy SQL Workflow applications.

Installing the Required Software

To successfully debug script in a SQL Workflow application, you are required to first install the Microsoft Script Editor (MSE) on the server where SQL Workflow Services are running.

To install MSE, you must install an Office application, such as Microsoft Word 2002, on that machine. After installing Word 2002, open the Tools menu, point to Macro, and click Microsoft Script Editor.

If this option is not installed, you will be prompted to install the program. Follow the instructions to install the Microsoft Script Editor (MSE). Subsequently, you can use ALT+SHIFT+F11 to launch MSE quickly from any Microsoft Office XP application.

After MSE starts, select the Debug option from the menu bar. Under this option, you will have a menu item that says "Install Web Debugging." This will only display the first time. Subsequently, you will see debugging options. These will be discussed later in this article.

Note

   

Installing Web debugging components requires you to restart the MSE. Click the Yes button when you are prompted to restart the MSE. If necessary, you can manually restart MSE by pressing ALT+SHIFT+F11 from any Office XP application; you can also search for the file mse7.exe and directly execute it.

To verify that the Web debugging has been installed, click the Debug menu item; the list of options should now display items such as Start, Processes, and so on.

In order for the MSE Debugger to trap the script errors, you must enable the JIT options.

To enable JIT options to trap script errors:

  1. Open the Tools menu.
  2. Point to Options.
  3. Click Debugging. When Debugging is selected, the panel on the right shows a button called JIT Settings.
  4. Click the JIT Setting button, and the JIT Debugging Setting dialog box appears.
  5. In the JIT Debugging Setting dialog box, select the Program type Script, and make sure both the check boxes, Enable Attach and Enable JIT Debugging, are selected.

These settings will now cause the SQL Workflow script to break in case of an error and display the error line in the MSE.

Debugging a Workflow Application

To test for successful debugging, you must first create a SQL Workflow solution if you do not have one already. Read the documentation that came with Microsoft Office XP Developer on how to create a SQL Workflow solution and add script to it.

**Note   **It is advisable to run the Workflow Process as a separate process. You can do this by changing the SeparateProcess property of your workflow to True in the Microsoft Office XP Developer Development Environment.

When you have a workflow application, add the following script to the Sub Create1_OnCreate:

Dim intA
Dim intB
Dim intC
intA = 5
intB = 10
intA = intA – 5
intC = intB / intA

This code's purpose is to simulate a division by zero error, which typically causes the script to fail and stop you from going any further. Now follow these steps to simulate how to cause the error and get debugging to work:

  1. Save the workflow and try to add a record to the workflow-enabled database.

  2. As soon as you attempt to save the records, you will be prompted by the Just-In-Time Debugging dialog box to choose a possible debugger. Select an instance of the MSE and click Yes.

  3. The next dialog box displays the name of the process and type of program that you are now debugging. Select Script and click OK.

    As soon as you click OK, the Debugger will display the error message "Microsoft VBScript runtime error: Division by zero" and the Break and Continue buttons. You will see that the SQL workflow event script is loaded in the editor. You will also see the line that caused this error to happen.

  4. Press Break to proceed with debugging. The script file is loaded under the Miscellaneous Files node in the Project Explorer and named MOD Workflow EngineEvent Script.

    • You can check the values of these variable / expressions by pressing CTRL+ALT+Q to launch QuickWatch. In the Expressions list, type the name of the variable, such as IntA or IntB, to see its current value.
    • To ignore this error and continue to execute the code, move the Show Next Statement arrow to the next line, and press F5 to continue executing the rest of the code.

Attaching to Code That Is Already Executing

You can attach the MSE to code that is already running and then step through the code to determine what code path is being executed. Here is how:

  1. Start the MSE, open the Debug menu, and click Processes.

    This will show a list of all the processes currently running on this machine.

  2. In the list of available processes, search for and select the modhost.exe with the title MOD Workflow Engine and of the type T-SQL, Win32, Script.

    **Note   **The Script Engine must be running for it to show up on this list. This will only happen when at least one call has been made to the script engine. If you do not see it in the list, perform a workflow action, such as adding a record or changing a state, so that the event script is triggered.

  3. Click on the Attach button.

  4. In the Attach to Process dialog box, make sure Script is selected, and click OK. The process, modhost.exe, is added to the bottom of the Debugged Processes list.

  5. Click the Break button.

    This will ensure that as soon as any code is executed it will break in the debugger. This happens for any code, with or without errors. This is helpful because as soon as event code execution starts, the debugger will stop the code. As a developer, you can then step through and see the sequence of steps, plus the values of variables, and trap any script errors.

  6. Close the Processes dialog box and re-attempt to add a record to the workflow-enabled table.

    This time you will notice a difference. The Script Debugger starts much sooner and breaks on the first line of code. Then, you can control the flow of the code based on the Step options provided by the MSE debugger.