Hopefully, with these examples, you understand the Active Server Page concept and how it can be
helpful. Again, this is only a cursory glance at VBScript and Active Server Page technology. If you are
going to do any serious development, you may want to read more about it.
ActiveX Data Objects
The ActiveX Data Objects (ADO), as explained previously, are a group of objects that are used to
communicate with a database. There is a hierarchy among the objects, but it is not enforced. That means
that they can all be created independently of one another. This allows greater flexibility and ease of use. This
section will explain some of the methods and properties that can be used to take advantage of the MySQL
ODBC Application Programming Interface (API).
ADO consists of three main objects. These three objects embody everything you can do with a
database. They are the Connection object, Recordset object, and the Command object. With these
three objects you can connect, query, and view results from any database.
Connection Object Properties and Methods
The first step in any API is to make a connection. ADO is no different. ADO uses the Connection object to
make its database connection. The Connection object has many properties and methods. These are
outlined in Table 13.1:
Table 13.1 Connection Object’s Properties and Methods
Method or Property Description
Attributes
Indicates one or more properties of the connection object.
CommandTimeout (^) Indicates how long to wait for a command to execute before
ending. The default is 30 seconds.
ConnectionString (^) The most important property of the Connection Object.
Provides all the information necessary to connect to a
database.
ConnectionTimeout (^) Indicates the amount of time to wait while trying to make a
connection before ending in an error.
CursorLocation (^) Indicates where to use the cursor. It is better to use the cursor
on the client for several reasons, one of which is to ensure the
operations you are trying to perform are supported.
DefaultDatabase
If not provided in the connection string, this is where the
connection will look for the name of the database to which to
connect.
Open()
Opens a connection to a database using the parameters
provided in the connection string.
Provider (^) Indicates the name of the provider used in the connection. With
MySQL it will be the ODBC OLE DB provider.
State (^) Indicates the current status of the connection.
Version
Indicates the ADO version of the object being used.
Making an ADO Connection
To connect to a MySQL database using VBScript and ADO, several steps need to be taken. They are as
follows:
- The first step is to declare a variable that will become the Connection object.
Dim mConn - The next step is to create the object and set your variable equal to it.
Set mConn = Server.CreateObject("ADODB.Connection") - Set the properties of the Connection object.
- mConn.CommandTimeout = 40
- mConn.ConnectionTimeout = 40