ActiveX Data Object
ActiveX Data Object
NET
Andrei Otcheretianski
Tomer Rothschild
Contents
Introduction
What is ADO.NET?
Data Access
Motivation - Why Moving to ADO.NET?
ADO.NET Objects
Content components
Managed-provider components
RDO:
Due to its optimization for Access, DAO was very slow when
used with ODBC data sources. To get round this, Microsoft
introduced Remote Data Objects (RDO).
RDO was designed specifically for access to ODBC data
sources. RDO is essentially a thin wrapper over the ODBC API.
ADO:
ActiveX Data Objects is the technology that gave its name to
ADO.NET (although in reality the differences are far greater than
the similarities).
ADO is merely an OLE DB consumer – a thin layer allowing
users of high -level languages to access OLE DB through a
simple object model.
In a way, ADO is to OLE DB more or less what RDO was to
ODBC
Cleaner Architecture
As we noted above, ADO is no more than a thin layer over
OLE DB.
ADO.NET can be much faster than ADO, as the providers
communicate directly with the data source.
XML Support
XML is absolutely integral to ADO.NET, and not just an add-
on.
As we shall see later on in the demo, XML is the format used
to serialize and transport DataSets.
Transaction Select
Data Table
Command Insert
DataColumn
Parameters Constraints
Update
DataRow
DataReader Delete
DataRelations
DB <XML>
Content components
Managed-provider components
DataRow
DataRelation
Managed-provider components
These components actually talk to the database to assist in data
retrievals and updates. Such objects include the Connection,
Command, Data Reader and Data Adapter.
Example:
"Network Library=DBMSSOCN; Data Source=132.245.124.37,1433;Initial
Catalog=myDatabaseName;User
ID=myUsername;Password=myPassword"
Connection Pooling
For example, using SQL Server .Net data provider you can configure
connection pooling by adding a name-value pairs to the connection
string: “[…];Max Pool Size=75; Min Pool Size=5”
Connections are pooled through an exact match algorithm on the
connection string!!! The pooling mechanism is even sensitive to
spaces between name-value pairs.
oCn.Close();
It's like a forward-only Recordset from the ADO and is very efficient
because it stores only one record in the memory at a time.
You can then pass the DataSet back to the Data Adapter, which will
go and update the database.
DataTable
DataSet
DataColumn
DataTable
DataRow
Relations
Constraints
XML Schema
Tables Collection
Relations Collection
ExtendedProperties Collection
Relations Collection
DataSet.Relations
The DataRelation objects define a parent-child relationship between
two tables based on foreign key values.
ExtendedProperties Collection
DataSet.ExtendedProperties
The ExtendedProperties is a user-defined properties collection.
Can be used to store custom data related to the DataSet, such as the
time when the DataSet was constructed.
DataRelationCollection
DataRelationCollection
ExtendedPropeties
ExtendedPropeties
DataTableCollection
DataTableCollection
DataTable
DataRowCollection
DataRowCollection
DataView DataRow
ChildRelations
ChildRelations
ParentRelations
ParentRelations
Constraints
Constraints
DataColumnCollection
DataColumnCollection
ExtendedProperties
ExtendedProperties DataColumn
ExtendedProperties
ExtendedProperties
PrimaryKey
// Connection String
String conStr = @"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:\
NWind.mdb";
//SQL Command
String sqlStr = "SELECT EmployeeID, FirstName, LastName FROM
Employees";
// Create a new DataAdapter object
OleDbDataAdapter da = new OleDbDataAdapter(sqlStr, conStr);
// Create a new DataSet
DataSet ds = new DataSet();
// Fill the DataSet
da.Fill(ds, "Employees");
db.Open();
transaction = db.BeginTransaction();
try
{
new SqlCommand("INSERT INTO TransactionDemo(Text) VALUES ('Row1')", db,
transaction).ExecuteNonQuery();
new SqlCommand("INSERT INTO TransactionDemo(Text) VALUES ('Row2');",db,
transaction).ExecuteNonQuery();
new SqlCommand("INSERT INTO CrashMeNow VALUES ('Die', 'Die', 'Die');", db,
transaction).ExecuteNonQuery();
transaction.Commit();
}
catch (SqlException sqlError)
{
transaction.Rollback();
}
db.Close();
Loading the XML file is not more complex than writing it.
Use DataSet.ReadXml(fileName) to load the data.
Wrap ReadXml call with try and catch because we can’t guarantee
that the file contains valid XML.
Generating a Schema
Command DataReader
SQLOLEDB
OleDb Provider
Good for almost anything other than SQL Server 7.0 or later,
or Oracle.
Using the ODBC data access through the OleDb is
discouraged – think of the architecture involved:
ADO.NET – COM interop – (optional) OLE DB services –
OracleClient Provider
Supports Oracle data types, as well as ref cursors
Avoids the cost of COM interop, and also employs Oracle-
specific optimizations
Asynchronous Commands
database command execution can take a long time.
ADO.NET 2.0 SqlClient now provides built-in SqlCommand
methods that provide asynchronous execution.
SqlDependency
Caching is good. But we should make sure it’s consistent with
the database.
Until now, this task was accomplished through triggers
MARS (contd)
DataSet
Web Page Web Service
Data Provider
HTTP