You are on page 1of 5



Database Structure:
Databases have a standard format of storing data; even if the database technology is
different. Databases store information in tables & records. Each record is assigned a key;
which is a unique identifier to differentiate records. Key values can be numeric or
alphanumeric so long as they're unique within the key column.

Open Data-Base Connectivity (ODBC):
ODBC is a standard for accessing data. It was designed to allow the programmer to
use a common set of routines to access the data stored in databases, regardless of the type of
database in which the data was stored. This meant that once the programmer was connected
to the database using ODBC, they could manipulate the data without worrying exactly where
the data was stored, or which type of database was storing it. It provided interface
transparency – so the programmer could access an Oracle database in the same way that they
accessed a SQL Server database.

Data Store:
Any persisted collection of information is a data store.
Aside from all the databases in the world, there's a wealth of other data out there that's
stored in other formats. It might be a spreadsheet containing your company finances, or a text
file containing a report on the conference you visited last month, or an email system and its
accompanying mail messages – but it's all data. We use the generic term data store to refer
to a receptacle that contains data.

Object Linking & Embedding Database (OLE-DB):
OLE-DB is the next step in the evolution of the anonymous data store. As well as
being more generic than ODBC, Microsoft has done a great deal of work to ensure that OLE-
DB is faster and easier to use than ODBC. Eventually it may well replace ODBC, although
that won't be for a long time yet, if only for the reasons that you often have to rely on third
parties writing new OLE-DB providers and then when they are available they are often more
expensive than existing ODBC drivers. So, consequently, there's a lot more ODBC drivers
out there still in use.
The idea behind OLE-DB is very similar to the idea behind ODBC – but in fact it
allows access to a much broader range of data stores. In fact, you'll notice that OLE-DB even
supports database connections through ODBC – so that effectively your generic OLE-DB
layer will allow you to connect to your legacy databases through your existing ODBC
OLE-DB introduces the notion of data providers and data consumers. The
relationship between a data provider and a data consumer is fairly obvious: a data provider is
something that provides data, and the data consumer is something that uses that data. In
reality, you might have several data providers – one for each different type of data store.

ActiveX Data Object (ADO):
ADO is a set of objects that allow programmers to program their data access logic
from languages like Visual Basic as well as scripting languages. ADO is a higher-level
model than OLE-DB, which means that it simplifies some of the complexities of
programming with OLE-DB. Thus, ADO is much easier to use than OLE-DB. The ADO
layer sits neatly between the application itself and the OLE-DB layer.

ADO Object Model:
The ADO Object Model has five main objects:
 Connection
 Command
 Recordset
 Record
 Stream

The following objects can be understood as follows:

Connection Object:
It acts as the link between the program and the data store. At one end, we have the
Connection object and at the other end, we have one or other data store. In between, we have
a connection that ties them together for as long as they need to communicate.
The syntax to create a Connection object in ASP:
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")

In order to actually establish the connection we use the Open method of the objConn
Connection object. The syntax for using the Open method is:
objConn.Open ConnectionString, UserId, Password, Options
The last four arguments are optional arguments – we don't have to specify any of them at the
time we call the Open method.

Once you have finished with a connection, you should Close it, in order to free associated
system resources:

ConnectionTimeout: Sets or returns the number of seconds to wait for a connection to
open. Default is 15.
ConnectionString: Sets or returns the details used to create a connection to a data source.
Provider: Sets or returns the provider name.

Open: Opens a connection.
Close: Closes a connection.
Execute: Executes a query, statement, procedure or provider specific text.

Command Object:
It allows you to run commands against the data store. It is used to execute a single
query against a database. The query can perform actions like creating, adding, and retrieving,
deleting or updating records.
The syntax to create a Command object in ASP:
Dim objComm
Set objComm = Server.CreateObject("ADODB.Command")

In order to run a command, we use the Command object's Execute method. The
Execute method has three parameters:
objCommand.Execute RecordsAffected, Parameters, Options
All three arguments are optional – if you omit any of them then the Execute method will
adopt the default value for that parameter.

ActiveConnection: Sets or returns a definition for a connection if the connection is closed,
or the current Connection object if the connection is open.
CommandText: Sets or returns a provider command.

Execute: Executes the query, SQL statement or procedure in the CommandText property.
Cancel: Cancels an execution of a method.

Record Object:
It allows you to run commands against the data store. It is used to execute a single
query against a database. The query can perform actions like creating, adding, and retrieving,
deleting or updating records. The Record object is used to represent a record in a recordset,
or to represent a file or even a folder in a file system or an email message in an email folder
The syntax to create a Record object in ASP:
Dim objRec
Set objRec = Server.CreateObject("ADODB.Record")

If you wanted to use the Record object to handle the files and folders on your web
server, you could use the Open method, passing a URL on your web server, like this:
objRecord.Open "Delete.asp", "URL=http://chrisu/BegASP/"
This method takes two arguments: the first is the file or folder that we're looking for and the
second is the URL to which any actions will apply.

ParentURL: Returns the absolute URL of the parent Record.
RecordType: Returns the type of a Record object.
State: Returns the status of a Record object.

Open: Opens an existing Record object or creates a new file or directory
CopyRecord: Copies a file or directory to another location.
MoveRecord: Moves a file or a directory to another location.
DeleteRecord: Deletes a file or directory.
Close: Closes a Record object.

Stream Object:
It allows the manipulation of data held in web resources, such as HTML files. The
Stream object is used to represent the most basic denomination of data – binary data or just
plain text.
The syntax to create a Stream object in ASP:
Dim objStr
Set objStr = Server.CreateObject("ADODB.Stream")

We use its Open method to open the object on a data source and hence access the
stream of data contained within:
objStream.Open "http://chrisu/BegASP/ReadMe.txt", adModeRead,
This example opens the Stream object on the stream of text contained in the file
ReadMe.txt, which is contained in a virtual directory of my web server machine.

State: Returns a value describing if the Stream object is open or closed.
CharSet: Sets or returns a value that specifies into which character set the contents are to be
translated. This property is only used with text Stream objects (type is adTypeText).
EOS: Returns whether the current position is at the end of the stream or not.
Open: Opens a Stream object.
WriteText: Writes character data to a text Stream object.
ReadText: Reads the entire stream, a line, or a specified number of characters from a text
Stream object.
Close: Closes a Stream object
Communication Information:
Each time you communicate with a data store, you need some form of connection.
There are three steps to supply information while creating a connection:

Step 1:- Connection String
It is a simple character string that lists all information needed to connect to a source
of data. It contains all of the following information:
• Provider : type of OLE-DB provider used in the connection
• Driver : type of ODBC driver
• Data Source : physical database path and file name
• Initial Catalog : name of the database
• User ID : user name needed to connect to the database
• Password : password of user specified in the User ID
• Persist Security Info : a Boolean, set to True if you want Windows to remember
your password
A Sample Connection String:
If we're connecting to an Access database then we might use a connection string like the
following (this is the connection string from the Connect.asp example above):
"Provider=Microsoft.Jet.OLEDB.4.0; " &_
"Data Source=C:\datastores\Movie2000.mdb;" & _
"Persist Security Info=False"

Step 2:- Data Link file
It is a method for connecting to your data store which helps to avoid the need to type
all of the code into a connection string by hand.
In Windows Explorer in Windows 98 or NT 4.0, you could create a data link file by
selecting the New option from the File menu – and thus generate and store the necessary
connection string information in a UDL (Universal Data Link) file. Since then, Microsoft has
deemed the ready accessibility of this functionality as 'confusing' to novices, and has thus
partially removed it from Windows 2000.

Step 3:- DSN
The Data Source Name (DSN) is another way to establish your connection string
without typing it explicitly – again, it involves getting Windows to do most of the hard work
for you. DSNs boast the advantage that they are very simple to use.
However, DSNs are now considered to be an outdated method of establishing a data
connection. Unfortunately they use ODBC drivers – so you lose many of the advantages that
come with using the OLE-DB providers, because DSNs don't support them.