Simple Recordsets - Reading Data - Page 2
November 27, 2000
So you've decided that ASP-ADO is the solution for your
situation, and you've learned how to set it up. Now you're ready
to begin using ASP-ADO to access and manipulate data within web
pages. This chapter discusses the simplest situation – the simple
task of reading the data. Although we are only reading the data,
we can still use it in several ways. Not only can we write it to
the page; we can also use the data in variables, expressions and
as the arguments for other functions.
Then we look at some of the techniques and problems with
presenting the data that we read in an HMTL table. Last, even
though VBScript implements only parts of Object Oriented
Programming, we'll include a few paragraphs to provide an
overview of the aspects of OOP that are available.
Preparing to use Simple Recordsets
One of my sailing coaches emphasized that yacht races are won or
lost long before the day of the race. Regattas are won during the
months of preparation and training prior to the starting gun.
Fortunately, ADO does not require many weeks of practicing tacks
and jibes in the cold rain; you just have to consider the
following three issues:
- Creating a DSN
- Having the correct User Identification, Password and Permissions
- Understanding the structure of the database
Step 1 - Create a DSN
In Chapter 2 we talked about creating an ODBC Data Source which
is referred to by a DSN – this is typically performed by a
systems administrator or other operator with access to the
server. To review: the DSN contains the information necessary to
make a physical connection into the database. This information
may include database name, path, server name, User ID, Password,
Driver name and other parameters.. These pieces of information
are wrapped up in a DSN, which is given a name. You need to get
the name of your DSN from your systems administrator prior to
using ASP-ADO.
If you are working on PWS you have access to the settings of your
Windows OS and can set your own DSN (also discussed in Chapter
2), by selecting Start | Control Panel | 32 bit ODBC and
following the steps of the wizard. In my development work I keep
two copies of the database – one on my development machine using
PWS and one on the server.
In Chapter 6, we will talk about how to make a connection without
a DSN.
Step 2 - User Identification and Password
I'm frequently approached by people seeking help with ADO, only
to find that the problem is not with their ADO code, but that
they do not have access rights to the database they're trying to
use. Even if you're only going to request a simple recordset, you
need to meet the security requirements of the database. Generally
this means that you present a User Identification
(UserID) and a password (pwd). Security
can be established at various levels, but you will need to get
this information from the owner or systems administrator of the
database.
Step 3 - Understand the Structure of the Database
Another obvious (but frequently overlooked) point of preparation
is understanding the structure of the database. ADO will always
produce errors if your commands don't use the exact spelling of
the tables, queries, views and fields. A more subtly but equally
deadly error arises when commands to the database conflict with
its relationships between tables. In Chapter 5 we'll look at a
technique for finding out the names of the fields, but you still
have to know the names of the tables. The structures of the
tables used in this book are provided in Appendix A.
Common Errors in preparation:
- Incorrect spelling of DSN
- DSN no longer exits, or name has been changed
- The DSN will not work if the file is moved to another location after the DSN is created (applies to Access and Excel files).
- DSN is of User or File type rather than a System DSN
- UserID or password is misspelled or incorrect
- Names of fields or tables are incorrectly known by plural or singular (e.g. Author instead of Authors)
- Type (number/text/date) of fields is not known correctly
Beginning ASP Databases
Beginning ASP Databases
Syntax for Simple Recordsets - Page 3
|