Listing 5: Accessing Data Without a Command Object ' Declare connection and connection string variables Dim conSqlServer, csSqlServer ' Declare command text variable Dim ctContacts ' Declare recordset variable Dim rsContacts ' Declare argument constants Const adPersistXML = 1 Const adStateOpen = 1 ' Create Connection object Set conSqlServer = CreateObject("ADODB.Connection") ' Define connection string csSqlServer = "Provider='sqloledb';Data Source='ws04';" & _ "Integrated Security='SSPI';Initial Catalog='AdventureWorks';" ' Open connection conSqlServer.Open csSqlServer ' Define the command text ctContacts = "SELECT TOP 10 FirstName, LastName FROM Person.Contact" ' Create and populate recordset object Set rsContacts = CreateObject("ADODB.Recordset") rsContacts.Open ctContacts, conSqlServer ' Save data to XML file rsContacts.Save "C:\Info\SqlServerContacts.xml", adPersistXML ' Clean up If rsContacts.State = adStateOpen then rsContacts.Close End If If conSqlServer.State = adStateOpen then conSqlServer.Close End If Set conSqlServer = Nothing Set csSqlServer = Nothing Set ctContacts = Nothing Set rsContacts = Nothing