![]()
Troubleshooting
and Debugging
Visual DataFlex 9.1 Web Applications
A
Data Access Worldwide White Paper
by Dennis Piccioni
January 27, 2004
Last Edited: January 30, 2004
This paper will show you:
Visual DataFlex Web Application Basics
A VDF Web Application consists of 2 areas where coding is done: ASP and VDF. When an ASP page that is part of a VDF Web Application is accessed from a browser, code execution starts on the ASP side. Then, code on the VDF side is called from ASP scripting code.
Here is a brief sample of what happens when a VDF Web Application report is called:
Top of page: (static HTML) print title of reportMiddle of page: (ASP script code) call VDF function that runs report (VDF report writes the report: a list of customers)Bottom of page: (static HTML) print footer of reportThe basic order of code execution is this:
- An ASP page is accessed in a browser.
- The ASP page code is executed from top to bottom, just as normal HTML is executed.
- If script code is encountered, the ASP script code executes, including making calls to VDF functions.
- The VDF functions execute.
- The ASP page code execution continues.
ASP script code can do a lot of other things besides making calls to VDF programs, but this is how VDF Web Application code is called and executed.
Since a VDF Web Application has 2 areas in which programming code is created, the VDF side and the ASP side, it is important to have the ability to debug code on both sides:
- Visual DataFlex Code
Visual DataFlex has a Debugger which can debug VDF code, including VDF code in VDF Web Applications.
- ASP Script Code
You should install a script debugger to enable you to debug code on the ASP side. We do not consider this optional for developing Web Applications!
If you have certain Microsoft development tools installed, such as Visual Studio or Visual Studio .Net, you may already have one or more script debuggers installed. The Microsoft Script Debugger is available as a free download from Microsoft. See the Additional Resources section for more information.
This paper will teach you how to get started using both debuggers, but you should plan to spend time learning both debuggers as expertly as possible.
An include file named DebugHelp.inc is added to each Web Application’s AppHtml\inc directory. This file allows you to turn on a "trace" mode, which will show all request data submitted to your ASP page by your browser. This is a very useful feature. It lets you see what data is actually being submitted to a server page. Often you will discover that a source of an error is that data being passed back to the server is different to what you expect. Also, this debugging feature is a great learning tool – it shows you how the POST/GET process works.
When trace debugging is enabled, all HTTP request information sent to a server page will be displayed as part of this server’s page HTML output. In other words, you will see the request information in your browser. Here is an example of what that output will look like:
----DEBUG INFORMATION---- content_length = 627 request_method = POST Customer__Recnum= 1 customer__customer_number= 1 customer__name= Data Access Worldwide customer__address= 14000 SW 119 Ave customer__status= Y customer__city= Miami customer__state= FL customer__zip= 331866017 customer__phone_number= customer__fax_number= customer__email_address= customer__credit_limit= 6320 customer__purchases= 10640 customer__balance= 10640 CUSTOMER__COMMENTS= Innovative software company & makers of Visual DataFlex... ChangedStates= findnext= > Index= 1 Querystring = ----END DEBUG INFORMATION----Adding DebugHelp to your ASP page
If you created your ASP page using the wizards, the code required to display request information has already been added to your page. If you are creating this code manually you will need to add two lines of code to your ASP page after the <body> HTML tag as follows:
<body> <% ' DebugMode =1 ' uncomment this for page get/post debug help %> <!-- #INCLUDE FILE="inc/DebugHelp.inc" -->Look at the Customer.asp file in the WebAppSample91 sample application for an example of this.
Enabling DebugHelp in your ASP page
To enable the debug help feature you need to set the VbScript variable DebugMode to 1.
Find line of code that reads <% ‘ DebugMode =1….%> and remove the comment. The line would look like the following:<% DebugMode =1 ' uncomment this for page get/post debug help %>Using the DebugMode variable for conditional debug code
Additionally, you can use the DebugMode variable to create pockets of conditional debug code within your application. You do this by creating an "If" statement block that tests for DebugMode as follows:
<% If DebugMode>0 then %> ....place your debug asp code here <% end if %>Here is an example of how this might be used:
<% If DebugMode>0 then %> Test code start<br> The current customer record is <%=oCustomer.ddValue("Customer.Recnum") %> Test code end<br> <% end if %>If debug mode is enabled, the following would be displayed in your browser page:
Test code start The current customer record is 123 Test code endWhen debug mode is disabled, you would not see this code.
Once debug mode is enabled, it will remain enabled until the session ends, or until the mode is explicitly turned off. This is very useful. Once debug mode is enabled, all pages that use the DebugHelp.inc will display debug information.
You can and should experiment with debug mode by running the WebAppSample91 application.
Logging Your Own Events to the VDF Web Application Event Log
You can write to the VDF Web Application Event Log from a Web Application using the LogErrorEvent and LogEvent messages. Both of these messages can be called from VDF or ASP code. See the Visual DataFlex Help for more information about these messages.
- LogErrorEvent can be useful for adding custom errors to your application (e.g. log an error someone attempts to login to an application and enters the wrong password).
- LogEvent can be useful for debugging or logging events in your application (to track certain operations, for example).
Example
Function DoRequestSave String sFilename Returns Integer Integer iVoid iEventType move 5 to iEventType Forward Get DoRequestSave sFilename To iVoid send LogEvent iEventType "Saving new record" Function_Return iVoid End_Function // DoRequestSaveThis example augments the DoRequestSave method a WBO to log a message to the event log whenever a new record is saved.
Example
dim iEventType iEventType = 5 oOrderWBO.Call "msg_LogEvent", iEventType, "Saving an order"This example makes logs the message "Saving an order" to the VDF Web Application Event Log using VBScript code in an ASP page.
Example
oOrderWBO.Call "msg_LogErrorEvent", DfErr_Operator, "Attempt to enter an invalid value for Customer City"This example makes logs the message "Attempt to enter an invalid value for Customer City" to the VDF Web Application Event Log using VBScript code in an ASP page.
When logging error events, you should use the predefined "generic errors" for the event numbers. The generic errors are reserved specifically for this type of use in applications. The generic errors are DfErr_Operator, DfErr_Program, DfErr_Compile and DfErr_Setup. Most likely, you will use the generic errors DfErr_Operator and DfErr_Program most often in your applications.
To see how to debug a VDF Web Application, and what happens during a VDF Web Application event, let's work through the scenario of saving a customer record in the WebAppSample91 sample application.
To set up this scenario, do the following:
- Open the Visual DataFlex Studio and open the WebAppSample91 workspace.
- Open the WebApp Sample application.
- Debug-run the program.
- Once the application is running, switch to the browser and click on the Login (for edit rights) page.
- Login using the username and password provided on the page.
Logging in here enables saving and deleting of records in this sample application.- Now click on the Customers page.
- Click on the > button to find the first record in the Customer table.
When the Save button on the Customers page is clicked, code execution begins in the ASP page. So, the first place to see what is happening is in the ASP code:
- In the Visual DataFlex Studio, select Open Web Markup from the Open Component toolbar combobox and open the Customer.asp file.
- Search for "Save" in Customer.asp. Stop when you reach this code:
if Request("save")<>"" thenThis code checks whether the Save button has been clicked.
We want to stop program execution when this happens.
- Add a stop statement right after the line of code above. The resulting code should look like this:
if Request("save")<>"" then stop oCustomer.call "set_pbReportErrors", 0
- Click on the Save button on the Customer page.
When the application reaches the stop statement, the application will break and start the Script Debugger.
The Script Debugger will display the Customer.asp page and execution will be stopped on the line with the stop statement.Note: If the Script Debugger does not start, the application never got to this line of code. In this case, you can place a breakpoint on the first line of the ASP page, then step through each line of code to determine what is happening.
- In the Script Debugger, Step Over lines of code until you reach this line:
err = oCustomer.RequestSave("Customer")This line calls the RequestSave function in the Visual DataFlex code of the application.
The next step is to stop execution in the VDF code when the call gets to the VDF side of the application.From the VDF documentation for the RequestSave function, we know that it calls the DoRequestSave event. We will place a breakpoint in this event in the VDF code. This event is not in the local code of most VDF Web Applications, but in the global packages distributed with VDF that are compiled as part of the application. We need to determine where, so we can place the breakpoint.
- In the Visual DataFlex Studio, search for text in multiple files.
Type "Function DoRequestSave" into the Text to find form.
Choose "Global Source" from the "Workspace Zone" comboform.The search returns RemoteEntryMixin.pkg.
- In the VDF Debugger, select RemoteEntryMixin.pkg from the source code comboform.
Search for "Function DoRequestSave". Stop when you reach this code::Function DoRequestSave String sFileName returns integer
- Place a breakpoint on the line "Get pbAllowSaveNew to bAllowSaveNew".
If you are new to the VDF Debugger, click on the blue dot to place the breakpoint. The blue dot should turn red to indicate that the breakpoint is set.Now we can return to the Script Debugger, where the execution of the ASP code is still stopped at the oCustomer.RequestSave call.
- In the Script Debugger, Run the program to continue execution.
A message box will pop up telling you the VDF Debugger has encountered a breakpoint.
- Click Ok on the message box and switch to the VDF Debugger.
The debugger is stopped at the breakpoint in DoRequestSave in RemoteEntryMixin.pkg.This tells us the program has properly executed the call from the ASP code to the VDF code.
Another method of checking whether DoRequestSave is called and what is being sent to it is to intercept this function at the WBO code level. This will allow us to place a breakpoint right in the WBO code instead of the global product package code. Intercepting the function at the WBO level could also be used to customize the save process.
- Close the browser running the WebAppSample91 application.
Doing so will also cause the VDF Debugger to close.
In the Visual DataFlex Studio, open the Customer.wo.
To intercept DoRequestSave at the WBO level, add the following code to the code of object oCustomer, right below the end of Function RunCustomerReport:Function DoRequestSave String sFilename Returns Integer Integer iVoid Forward Get DoRequestSave sFilename To iVoid Function_Return iVoid End_Function // DoRequestSave
Compile and debug-run the program. Follow the same steps as above to login, go to the Customers page and find a customer record. In the VDF Debugger, open the Customer.wo file and search for "Function DoRequestSave". Once you have found the augmented code we placed in this WBO, place a breakpoint on the line "Forward Get DoRequestSave sFilename To iVoid". Click on the Save button on the Customer page. When the Script Debugger stops again at the stop statement, run the program to continue execution. A message box will pop up telling you the VDF Debugger has encountered a breakpoint.- Click Ok on the message box and switch to the VDF Debugger.
The debugger is stopped at the breakpoint in DoRequestSave in Customer.wo.
There are 2 logs you should always check for more information when you are troubleshooting Web Applications.
This log contains application-specific error messages.
To view the VDF Web Application Event Log, follow these steps:
In the VDF Web Application Administrator, expand the TreeView of web applications and select the application in question.
Expand the tree for the application and select the Event Log.
Tip: You may see a lot of "Session Started" and "Session Closed" entries in the Event Log. If you do not want to log each of these events, and instead only want to log error messages from your web application, do the following:
Right-click on your application and select Properties.
Uncheck the "Log all Access to the Web Application" checkbox.
This will stop all events from being logged, but will still log errors.Make sure the Maximum log entries is set to 0 for unlimited entries.
This log contains error messages that are not specific to any particular Web Application, but are more systemic to Visual DataFlex Web Applications, such as invalid registration codes. Here you will also see error messages about other applications that may affect VDF Web Application Server, such as Internet Information Server errors.
To view the Windows Event Viewer's Application Log, select
Start > Control Panel > Administrative Tools > Event Viewer.
Select Application in the TreeView.
You can also launch the Windows Event Viewer from the VDF Web Application Administrator's Tools menu.
Here are steps to analyzing and solving some of the most common Web Application errors. Please also see the Additional Resources section.
This error means that the browser could not show the requested page. The error is also often 'Page not Found' or 'Object not Found', but as long as the error code is 404, the cause is the same. This error code is returned from the server that is supposed to serve the page, rather than the browser itself. The the most 'typical' reason why you might see this error when working with VDF Web Application Server is that the file you are trying to access (usually default.asp) is not listed as a default document for the virtual directory.
To resolve this, do the following:
error '80004005' Unspecified error /VirtualDirectoryName/global.asa, line 15
This error can occur for any number of reasons. There are a number of ways of obtaining more meaningful information when this error occurs.
- Check the Windows Event Viewer.
- Check the event log for the VDF Web Application in question.
- Make sure there is a program filled in (and it is the correct program) for the Web Application in the VDF Web Application Administrator.
- Open the VDF Web Application Administrator
- Expand the TreeView of applications and select the application in question
- Right-click and choose Properties
- Make sure the correct program is entered into the Filename window
- While here, also make sure that the Disable Web Application checkbox is not checked
- Debug-Run the Application
- There might be an error message or other Windows popup dialog that may be hidden when running the application in normal mode using the VDF Web Application Server. When running in debug mode, you will see these types of things.
- You may be able to stop the Application's execution in the debugger and see where the program is "stuck".
Microsoft VBScript compilation (0x800A03F6) 'End' expected /packing/inc/DebugHelp.inc, line 14
You will sometimes encounter this error pointing to one of the include files provided with VDF (typically DebugHelp.inc). Most likely this is caused by some other scripting error in your ASP code, such as a missing 'end if', and the error is only 'caught' in the include file. Your best bet for debugging this problem is usually to double-check the last area of ASP code you worked on.
This error can be caused by an incorrect firewall configuration, particularly with firewall software. To test this, you could try to temporarily disable the firewall, then see if the error subsides. If so, re-enable your firewall and configure it to allow access to this Web Application and/or Web server.
This error is often caused by a bug in Crystal Reports version 8.0. If you are running that version, please take these steps:
- Download and install the patch for this Crystal Reports bug available from http://support.businessobjects.com/communityCS/FilesAndUpdates/scr8_webregfix.exe.asp
- Reinstall Visual DataFlex 9.1. You can reinstall over your existing installation without having to uninstall it first.
VDF Web Application Debugger Limitations
The Visual DataFlex Web Application Server Debugger is a separate program from the Visual DataFlex Web Application Server, which runs on a Windows Server as a Service. As a result of this, the following are not supported:
When you enable Process Pooling in a VDF Web Application, the Application will run using Process Pooling in the VDF Web Application Server, which supports process pooling, but not in the VDF Debugger, which does not support process pooling. You can still debug your application if Process Pooling is enabled, it just won't run in the Debugger as a Process Pooled session.
The Visual DataFlex Debugger only supports debugging applications locally on the same machine. Remote debugging is not supported with either Windows or Web applications. However, you can run the application on your machine and connect to a database on a separate machine. This is probably the most common configuration for Windows applications. This involves setting the various paths in the workspace file so that it points to the remote machine. Often this is accomplished by using relative pathing and referencing the .exe file and the workspace located on a separate machine.
By default, variables in VBScript do not need to be declared. This can easily cause problems that go undetected during development, for example, an accidental change of a variable name will not be trapped as an error.
The option explicit statement causes declaration of errors for undeclared variables. We highly recommend always using this option.
Example:
option explicit dim Error iError = oCustomerWBO.RequestSave "Customer"
In this example, the last line would generate a VBScript error message, because the declared variable Error does not match the used variable iError:
Microsoft VBScript runtime error '800a01f4' Variable is undefined: 'iError' /VirtualDirectoryName/FileName.asp, line ###
Here are some brief explanations of terms that are important when working with Visual DataFlex Web Applications. You are expected to be familiar with some of the terms that are not explained here (i.e. HTML, URL).
Software technology by Microsoft that allows execution of HTML code with embedded scripting.
HTTP server software by Microsoft, which allows, among other things, execution of ASP pages. The minimum IIS version requirement for Visual DataFlex Web Application Server is 4.0.
Any virtual directory used by IIS can have a set of HTML and/or ASP pages listed as default documents. This means that, when the URL of the virtual directory is typed into the browser's location bar without specifying a page in the virtual directory, the server automatically looks for any default documents specified and displays the first default document found in the browser.
For example, when launching the WebAppSample91 sample application, you typically access the URL http://localhost/DAW.Examples.Web.WebAppSample91, but http://localhost/DAW.Examples.Web.WebAppSample91/default.asp is actually loaded in your browser.
Here is how to configure default documents for a virtual directory:
- Start > Control Panel > Administrative Tools > Internet Information Services
- Expand Servers + the Server name your application is hosted on + Web Sites + Default Web Site
- Select the virtual directory for your application
- Right-click and select Properties
- Choose the Documents tab
- Make sure that "Enable Default Document" is checked
- Make sure that the correct default documents are listed
A Virtual Directory maps a physical folder on a disk drive (the ASP/HTML folder of a Web Application) with a URL. It provides for an access method to a Web Application on a Web Server.
For example, the virtual directory for the WebAppSample91 sample application is DAW.Examples.Web.WebAppSample91. The physical folder for this virtual directory is C:\Program Files\Visual DataFlex 9.1\Examples\Web\WebAppSample91\AppHtml.
When accessing it on the local machine (the machine you are currently working on), the Web Server is usually be accessed via http://localhost. The combination of the server name and the virtual directory name results in the URL to your application: http://localhost/DAW.Examples.Web.WebAppSample91.
This is the most common programming component on the VDF code side of a WebApp. A WebApp is usually made up of one or more WBOs, each of which contains a set of DataDictionaries, methods and child objects.
Contacting Data Access Worldwide
Data Access
Worldwide
14000 SW 119 Ave
Miami, FL
33186
305-238-0012
Domestic Sales: 800-451-3539
Fax:
305-238-0017
email: sales@dataaccess.com
Newsgroup Server:
news.dataaccess.com
Internet:
http://www.dataaccess.com
Data Access Worldwide - Asia Pacific
Suite 5, 333 Wantirna Road, Wantirna VIC 3152 Australia
Phone: +61 3 9800 4233 f: +61 3 9800 4255
Sales: asiapacific@DataAccess.com
Support: support.asiapacific@DataAccess.com
Internet: http://www.DataAccess.com/AsiaPacific
Data Access Worldwide - Brasil
Av.Paulista, 1776 - 21st.Floor
São Paulo -SP - Brazil
CEP 01310-921
Phone: 5511-3262-2000
Fax 5511-3284-1579
Sales: info@dataaccess.com.br
Support: suporte@dataaccess.com.br
Internet: http://www.dataaccess.com.br
Data Access Worldwide - Europe
Lansinkesweg 4
7553 AE Hengelo
The Netherlands
Telephone: +31 (0)74 - 255 56 09
Fax: +31 (0)74 - 250 34 66
Sales: info@dataaccess.nl
Support: support@dataaccess.nl
Internet: http://www.dataaccess.nl
Data Access Technical
Support
800-451-3539 / 305-232-3142
email: support@dataaccess.com
Visit our Support Home page to see all of our Support
options: http://www.dataaccess.com/support
Data Access Technical Knowledge
Base http://www.dataaccess.com/kbase
Many answers to technical problems can be found
online in the Data Access Technical Knowledge Base. Here, you can access the
same live data that Data Access Worldwide technical support and development
staff use to
enter and track technical articles.
Copyright Notice
This document is property of Data
Access Corporation. With credit to Data Access Corporation for its authorship, you are encouraged to reproduce this
information in any format either on paper or electronically, in whole or in part. You may publish this paper as a stand
alone document within your own publications conditional on the maintenance of the intent, context, and
integrity of the material as it is presented here.
DataFlex is a registered trademark of Data Access Corporation.
NO LIABILITY FOR CONSEQUENTIAL DAMAGES
To the maximum extent permitted by applicable law, in no
event shall Data Access Corporation be liable for any special, incidental,
indirect, or consequential damages whatsoever (including, without limitation,
damages for loss of business profits, business interruption, loss of business
information, or any other pecuniary loss) arising out of the use of or inability
to use any information provided in this document, even if Data Access
Corporation has been advised of the possibility of such damages. Because some
states and jurisdictions do not allow the exclusion or limitation of liability
for consequential or incidental damages, the above limitation may not apply to
you.