Microsoft Word - Sam's Teach Yourself MySQL in 21 Days - SAMS.doc

(singke) #1
mConn.CursorLocation = 3
A little side note. There is a bug within IIS 4. The interpreter will not interpret the VBScript
constants, so the number that is represented by that constant has to be used. Normally,
you would use the adUseClient constant instead of the number 3. This will show up
again when issuing the Open command of the Recordset object.


  1. Create the connection string.

  2. mConn.ConnectionString="server=10.1.1.50;db=Meet_AGeek;" &
    driver=MySQL;uid=root;pwd=tacobell"


The connection string is made up of the following information:
ƒ Server—Can be a name or an IP
ƒ db—The name of the database
ƒ driver—The name of the ODBC driver to use
ƒ uid—The username of somebody who has permission to connect to
this database
ƒ pwd—The password for the uid

The components of the connection string can appear in any order as long as they are all
present. If you are going to use a DSN for a connection, the only thing you need in your
connection string is the name of the DSN.
So if you had a DSN named "MeetAGeek", you could use the following connection
string, as long as your DSN is configured correctly:
mConn.ConnectionString = "DSN=MeetAGeek"


  1. The next step is to open the connection. This takes the connection string, applies
    it to the driver, and connects to the database. To do this, use the following
    syntax:[/nl_list]
    mConn.Open


That’s all there is to it. If you follow these five simple steps, you can connect to any MySQL database, or
any other database for that matter. That’s the beauty of this technology. The same code you used here
can be applied to any other database as long as you supply the correct information.

It is recommended that you use the DSN-less type of connection. By using this method, you avoid doing
any extra work or relying on someone else to do it for you. With a DSN connection, someone must
create a system DSN on the server. This isn’t hard to do, if you are right there. When you are trying to
do it remotely, you will have some problems. Plus, you are relying on a piece of information that is
beyond your control. What if the server crashes and they have to reload NT? What happens to all your
programs that rely on that DSN? What if they forget to redo your DSN? Now you’re in real trouble. The
best scenario is to create DSN-less connections. That way, everything is in your control.

Command Object Properties and Methods


The next important object in the ADO object list is the Command object. This object has many uses. It can
execute SQL statements that do not return a resultset, be used to manipulate the structure of your database,
and it can issue statements that are specific to a database, such as MySQL. The Command object, like the
Connection object, has many methods and properties. These are listed with brief descriptions in Table
13.2.
Table 13.2 Command Object’s Properties and Methods


Method or Property Description
ActiveConnection
Sets the connection to use for any commands. Can be set to an
open Connection object.
CommandText
A string that acts as the command. Can be an SQL command or,
in some cases, just the name of a table. Pretty much anything
you can type into the MySQL monitor program can be used here.
CommandTimeout
Indicates how long to wait for a command to execute before it
times out.

CommandType (^) Indicates what type of command you will be issuing. The values
can be a command string ( 1 ) or table ( 2 ). The other command
types do not apply to MySQL because they deal with features

Free download pdf