ADO is a specially designed Microsoft technology used to access databases from web pages. Some working knowledge of Microsoft Access and VB Script is required to understand this tutorial fully.
In ASP people use ADO (ActiveX database objects) to get data from database. ADODB is comprised of 3 main objects: Connection, RecordSet, Command. We would discuss the first two in this tutorial. The ADODB.Connection object opens up an ODBC or OLEDB connection to a database through database drivers to perform operations in the database. For this, you first have to create an instance of the object:
1 2 3 4 5 |
<% Set objConn = Server.CreateObject ("ADODB.Connection") %> |
When you are finished up with the connection you can clean up:
1 2 3 4 5 6 |
<% Conn.close set objConn = Nothing %> |
Conn is basically a reference to the connection, which you can name any way. Next, you have to open up a database. This can be done by either using a Data Source Name (DSN) or a connection string. Common method among the developers is connection string because DSN required a setup by administrator. A DSN is really just a shortcut name for a connection string. But with a connection string, you can move your database around without having to change the DSN. There are two connection strings. One uses ODBC the other uses OLEDB. We will use OLEDB since it is faster and simpler. An example:
1 2 3 4 5 6 7 |
<% Dim strConnect strConnect = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = "& _ Server.MapPath ("mydata.mdb") %> |
The code uses the Server.MapPath() function to get the physical path. In case of password protected database:
1 2 3 4 5 6 7 |
<% Dim strConnect strConnect = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = "& _ Server.MapPath ("mydata.mdb") & "PWD = yourpass" %> |
Finally, the connection to the database is opened by using the open property, as follows:
1 2 3 4 5 6 7 8 9 |
<% Dim strConnect strConnect = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = "& _ Server.MapPath ("mydata.mdb") & "PWD = yourpass" Set objConn = Server.CreateObject ("ADODB.Connection") objConn.open strConnect %> |
This pretty much completes the retrieval of data from the required web pages. This process does not require much expertise but it does require understand of Microsoft Access and VBScript.