Está en la página 1de 7

What is ADO?

 ADO is a Microsoft technology


 ADO stands for ActiveX Data Objects
 ADO is a Microsoft Active-X component
 ADO is automatically installed with Microsoft IIS
 ADO is a programming interface to access data in a database

Accessing a Database from an ASP Page


The common way to access a database from inside an ASP page is to:

1. Create an ADO connection to a database


2. Open the database connection
3. Create an ADO recordset
4. Open the recordset
5. Extract the data you need from the recordset
6. Close the recordset
7. Close the connection

Create a DSN-less Database Connection


The easiest way to connect to a database is to use a DSN-less connection. A DSN-less connection
can be used against any Microsoft Access database on your web site.

If you have a database called "northwind.mdb" located in a web directory like "c:/webdata/", you
can connect to the database with the following ASP code:

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
%>

Note, from the example above, that you have to specify the Microsoft Access database driver
(Provider) and the physical path to the database on your computer.

Create an ODBC Database Connection


If you have an ODBC database called "northwind" you can connect to the database with the
following ASP code:

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "northwind"
%>

With an ODBC connection, you can connect to any database, on any computer in your network,
as long as an ODBC connection is available.
An ODBC Connection to an MS Access Database
Here is how to create a connection to a MS Access Database:

1. Open the ODBC icon in your Control Panel.


2. Choose the System DSN tab.
3. Click on Add in the System DSN tab.
4. Select the Microsoft Access Driver. Click Finish.
5. In the next screen, click Select to locate the database.
6. Give the database a Data Source Name (DSN).
7. Click OK.

Note that this configuration has to be done on the computer where your web site is located. If
you are running Personal Web Server (PWS) or Internet Information Server (IIS) on your own
computer, the instructions above will work, but if your web site is located on a remote server,
you have to have physical access to that server, or ask your web host to do this for you.

The ADO Connection Object


The ADO Connection object is used to create an open connection to a data source. Through this
connection, you can access and manipulate a database.

Connection Object
The ADO Connection Object is used to create an open connection to a data source. Through this
connection, you can access and manipulate a database.

If you want to access a database multiple times, you should establish a connection using the
Connection object. You can also make a connection to a database by passing a connection string
via a Command or Recordset object. However, this type of connection is only good for one
specific, single query.

ProgID
set objConnection=Server.CreateObject("ADODB.connection")

Properties

Property Description

Attributes Sets or returns the attributes of a Connection object


CommandTimeout Sets or returns the number of seconds to wait while attempting to execute a
command

ConnectionString Sets or returns the details used to create a connection to a data source

ConnectionTimeout Sets or returns the number of seconds to wait for a connection to open

CursorLocation Sets or returns the location of the cursor service

DefaultDatabase Sets or returns the default database name

IsolationLevel Sets or returns the isolation level

Mode Sets or returns the provider access permission

Provider Sets or returns the provider name

State Returns a value describing if the connection is open or closed

Version Returns the ADO version number

Methods

Method Description

BeginTrans Begins a new transaction

Cancel Cancels an execution


Close Closes a connection

CommitTrans Saves any changes and ends the current transaction

Execute Executes a query, statement, procedure or provider specific text

Open Opens a connection

OpenSchema Returns schema information from the provider about the data source

RollbackTrans Cancels any changes in the current transaction and ends the transaction

Events

Note: You cannot handle events using VBScript or JScript (only Visual Basic, Visual C++, and
Visual J++ languages can handle events).

Event Description

BeginTransComplete Triggered after the BeginTrans operation

CommitTransComplete Triggered after the CommitTrans operation

ConnectComplete Triggered after a connection starts

Disconnect Triggered after a connection ends

ExecuteComplete Triggered after a command has finished executing


InfoMessage Triggered if a warning occurs during a ConnectionEvent operation

RollbackTransComplete Triggered after the RollbackTrans operation

WillConnect Triggered before a connection starts

WillExecute Triggered before a command is executed

Collections

Collection Description

Errors Contains all the Error objects of the Connection object

Properties Contains all the Property objects of the Connection object

ADO ADO.Net
ADO is base on COM : Component Object Modelling based. ADO.Net is based on CLR : Common Language Runtimebased.
ADO stores data in binary format. ADO.Net stores data in XML format i.e. parsing of data.
ADO can’t be integrated with XML because ADO have limited access ADO.Net can be integrated with XML as having robust support of
of XML. XML.
In ADO, data is provided by RecordSet. In ADO.Net data is provided by DataSet or DataAdapter.
ADO is connection oriented means it requires continuous active ADO.Net is disconnected, does not need continuous connection.
connection.
ADO gives rows as single table view, it scans sequentially the rows ADO.Net gives rows as collections so you can access any record and
using MoveNext method. also can go through a table via loop.
In ADO, You can create only Client side cursor. In ADO.Net, You can create both Client & Server side cursor.
Using a single connection instance, ADO can not handle multiple Using a single connection instance, ADO.Net can handle multiple
transactions. transactions.

Overview of ADO.NET Namespaces and Classes

System.Data and its five supporting namespaces define the ADO.NET functionality. In this
article, you'll take a brief look of these namespace. These namespaces reside in the
System.Data.dll assembly. Figure shows the contents of this assembly in the IL DASM utility.
Figure: The system. Data assembly contents in the IL DASM utility

The six ADO.NET namespaces are the System.Data, System.Data.Common,


System.Data.Oledb, Microsoft.Data.Odbc, System.Data.SqlClient, and System.Data.SqlTypes.

The System.Data namespace is the core namespace of ADO .NET. It consists of the base
classes for the ADO.NET architecture. All data providers use these classes. It defines classes
that represent table, columns, row, and datasets some common classes from this namespace
DataView, DataViewManager DataSet, DataTable, DataRow, DataColumn, and DataRelation.
To use these classes in your applications, you need to add a reference to the System.Data
namespace.

NOTE: All classes in the .NET base library are derived from the Object class and represent a
type. Some authors and documentation also use word type for a .NET framework class.
The System.Data.Common. namespace defines common classes. These classes are base
classes for concrete data provider classes. These classes are shared among all data providers.
DBConnection, DataAdapter, DBDataAdapter, DataColumnMapping and DataTableMapping are
some of the classed defined in this namespace. To use these classes in your application, you
need to add a reference to the System.Data.Common namespace in your application.

The System.Data.OleDb namespace defines classes to work with OLE-DB data sources
using.NET OleDb data providers. To work with an OLE-DB data source, you must have an OLE-
DB provider for that data source. Each data provider component has a class corresponding to it.
These classes start with OleDb followed by the component. For example, OleDbConnection
class represents a Connection object. Some of the common classes of this namespace are
OleDbDataAdapter, OleDbDataReader, OleDbCommand, OleDbCommandBuilder OleDbError,
OleDbParameter, OleDbPermission, and OleDbTransaction. To use these classes in your
application, your need to add a reference to the System.Data.OleDb namespace in your
application.

Similar to the System.Data.OleDb namespace, the Microsoft.Data.Odbc namespaces define


ODBC.NET data provider classes to work with the ODBC data sources. To work with ODBC
data source, you need to install an ODBC driver for a database. The Microsoft.Data.Odbc
namespace classes start with odbc, followed by the component. For example, the
OdbcConnection class represents a connection object. Some of the common classes of this
namespace are OdbcDataAdapter, OdbcDataReader, OdbcCommand, OdbcCommandBuilder,
OdbcError, OdbcParameter, OdbcPermission, and OdbcTransaction. To use these classes in
your application, you need to add a reference to the Microsoft.Data.Odbc namespace in your
application.
The System.Data.SqlClient namespaces define Sql.NET data provider classes to work with SQL
server 7.0 or later databases. Similar to ODBC and OleDb classes, the classes in this
namespace start with sql. For example, common classes are SqlConnection, SqlDataAdapter,
SqlCommand, SqlDataReader, and SqlTransaction.

The last namespace, System.DataSqlTypes, providers a group classes representing the specific
types found in SQL server. Some of these classes are SqlBinary SqlMoney, SqlString,
SqlDouble, SqlDateTime, and SqlNumeric.

También podría gustarte