Listing 4: Accessing a MySQL Database ' Declare connection and connection string variables Dim conMySQL, csMySQL ' Declare command and command text variables Dim cmdContacts, ctContacts ' Declare recordset variable Dim rsContacts ' Declare argument constants Const adPersistXML = 1 Const adStateOpen = 1 ' Create Connection object Set conMySQL = CreateObject("ADODB.Connection") ' Define connection string csMySQL = "Provider=msdasql;DSN=MySQL_AW;" ' Open connection conMySQL.Open csMySQL ' Create Command object and set the connection Set cmdContacts = CreateObject("ADODB.Command") Set cmdContacts.ActiveConnection = conMySQL ' Define and set the command text ctContacts = "SELECT FirstName, LastName FROM Contacts LIMIT 10" cmdContacts.CommandText = ctContacts ' Create and populate recordset object Set rsContacts = CreateObject("ADODB.Recordset") rsContacts.Open cmdContacts ' Save data to XML file rsContacts.Save "C:\Info\MySQLContacts.xml", adPersistXML ' Clean up If rsContacts.State = adStateOpen then rsContacts.Close End If If conMySQL.State = adStateOpen then conMySQL.Close End If Set csMySQL = Nothing Set cmdContacts = Nothing Set ctContacts = Nothing Set rsContacts = Nothing