adOpenStatic Logo
Contact Ken
Copyright 2000 -

Defining the ADO Constants
ASP has no inherent knowledge of what the CursorType, LockType and Options constants (eg adOpenForwardOnly or adLockOptimistic) actually mean. Instead you need to define them. In this respect the use of <%Option Explicit%> is strongly recommended as errors regarding undefined variables will automatically point you to the fact that your ADO constants are not defined.

There are three methods of defining constants.

Method 1 - Strongly Recommended
Put the following code into your global.asa in the Application_OnStart subroutine (all on one line):
<!-- METADATA TYPE="TypeLib" FILE="C:\Program Files\Common Files\system\ado\msado15.dll" -->
You'll need to replace the drive letter above if your NT Boot partition is not drive c: By including a reference to the ADO type library you make ASP "aware" of the ADO constants that you are using.

Method 2 - Recommended
Not as highly recommended as Method 1 is including the file in whatever pages require access to the ADO constants. The file should be on your hard drive if you've installed Microsoft IIS or PWS. Typically it can be found in c:\program files\common files\system\ADO\

Copy the file to your includes directory on your webserver (eg c:\inetpub\wwwroot\includes\) and use the following code on the pages that require access to the file:
<!-- #include virtual="/includes/" -->
Since the file is quite large, you could choose to create a user-defined file which contains only the constants that you use and include that instead. Simply open in Notepad, delete the constants you don't need, save the file as adoConst.asp (or similar) and include this new file instead.

Method 3 - Not Recommended
You can define the constants inline on the page. This is not a recommended practise.

NOTE: It is also possible to supply the underlying values of the ADO Constants directly into the Recordset's Open method. The use of these "magic numbers" (as Phil Paxton calls them) is to be strongly discouraged. Nearly 50% of problematic code that I have encountered resulted from people choosing incorrect numbers to supply to the .Open method, and the person looking over the code has to constantly look up the documentation to find out what numbers correspond to what constants.

Use of "magic number" results in code that looks like this:
objRS.Open strSQL, strConnect, 3, 1, &H0001
Even is these numbers just happened to be valid values could you tell me what they stood for? If you can then you've been spending too much time memorising ADO constants! The programmer that puts objRS.AddNew on the line after the above is in for a nasty suprise.

Step 3 - Making sure your constants are not conflicting
Back to FAQ listing.