ASP Database Fundamentals (Part 1) - Establishing The Connection
(Page 4 of 6 )
ADO is an object-oriented programming interface. In layman's terms, this means you will be working with different "objects" in order to communicate with the database. The first of these objects you will work with is the Connection Object.
Lets take a look at a code sample that creates a database connection object:
<%
ConnectionString = "DSN=MyDB"
set conn = server.createobject("adodb.connection")
conn.open ConnectionString
%>
In the above example, you can see that we create an object called "conn", which is defined as an ADO connection. Once we have an object for the connection, we attempt to open that connection using the open method of the object.
One thing I'd like to mention here is you will see that I am referencing the "connection" object of the "adodb" class in my createobject method. By default that statement will fail, since IIS does not know that that object is or how to make it. There are two ways to make this information known to IIS.
The first is to create an object reference to the ADO library inside your GLOBAL.ASA file. See my article on the GLOBAL.ASA to see how this is done.
Secondly, you can use the ADOVBS.INC module. This is an include file that comes with IIS, that you can include in any ASP page. It contains the appropriate declarations to be able to used the ADO objects within your code.
Next: Closing The Connection >>
More ASP Articles
More By Rich Smith