ASP uses the ADO protocol. ADO stands for ActiveX Data Objects, and is the latest Microsoft technology for connecting to databases.
ADO is very flexible when it comes to creating connections. For simplicity, we will stick to one way of doing it.
We will use the Connection and Recordset objects. The steps are as follows:
Declare the variables.
Instantiate the Connection object.
Open the Connection.
Instantiate the Recordset object
Open the Recordset
Process the records
Close the Recordset and Connection
Set the objects to Nothing
The code would look like this:
A few notes on the code:
Where you see , replace that with the actual Data Source Name you created in an earlier lesson. You still need the double-quotes around it, but not the angle brackets.
Where you see , replace that with either an SQL Select statement or the name of a table or select query in the database. You still need the double-quotes around it, but not the angle brackets.
Setting your objects to Nothing at the end helps speed up the process of freeing the memory.
Set objConnection = Server.CreateObject("ADODB.Connection")
Set objRecordSet = Server.CreateObject("ADODB.RecordSet")
objRecordSet = objConnection.Execute("")
While Not objRecordSet.EOF
‘Processing goes here
Set objRecordSet = Nothing
Set objConnection = Nothing