Sie sind auf Seite 1von 4

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 ! ADO is a programming interface to access data in a database

Accessing a Database from an A!" "age


#he common way to access a database from inside an A!" page is to$ %& 'reate an ADO connection to a database (& Open the database connection )& 'reate an ADO recordset *& Open the recordset +& ,-tract the data you need from the recordset .& 'lose the recordset /& 'lose the connection

DO .NET
Most applications need data access at one point of time ma0ing it a crucial component when wor0ing with applications& Data access is ma0ing the application interact with a database1 where all the data is stored& Different applications have different re2uirements for database access& 34 &5,# uses ADO &5,# 6Active X Data Object7 as it8s data access and manipulation protocol which also enables us to wor0 with data on the nternet& 9et8s ta0e a loo0 why ADO &5,# came into picture replacing ADO& Evolution of ADO.NET #he first data access model1 DAO 6data access model7 was created for local databases with the built-in :et engine which had performance and functionality issues& 5e-t came ;DO 6;emote Data Object7 and ADO 6Active Data Object7 which were designed for 'lient !erver architectures but1 soon ADO too0 over ;DO& ADO was a good architecture but as the language changes so is the technology& With ADO1 all the data is contained in a recordset object which had problems when implemented on the networ0 and penetrating firewalls& ADO was a connected data access1 which means that when a connection to the database is established the connection remains open until the application is closed& 9eaving the connection open for the lifetime of the application raises concerns about database security and networ0 traffic& Also1 as databases are becoming increasingly important and as they are serving more people1 a connected data access model ma0es us thin0 about its productivity& <or e-ample1 an application with connected data access may do well when connected to two clients1 the same may do poorly when connected to %= and might be unusable when connected to %== or more& Also1 open database connections use system resources to a ma-imum e-tent ma0ing the system performance less effective& Why ADO.NET?

#o cope up with some of the problems mentioned above1 ADO &5,# came into e-istence& ADO &5,# addresses the above mentioned problems by maintaining a disconnected database access model which means1 when an application interacts with the database1 the connection is opened to serve the re2uest of the application and is closed as soon as the re2uest is completed& 9i0ewise1 if a database is >pdated1 the connection is opened long enough to complete the >pdate operation and is closed& 4y 0eeping connections open for only a minimum period of time1 ADO &5,# conserves system resources and provides ma-imum security for databases and also has less impact on system performance& Also1 ADO &5,# when interacting with the database uses XM9 and converts all the data into XM9 format for database related operations ma0ing them more efficient&

The ADO.NET Data Architecture Data Access in ADO&5,# relies on two components$ Data!et and Data "rovider& DataSet #he dataset is a disconnected1 in-memory representation of data& t can be considered as a local copy of the relevant portions of the database& #he Data!et is persisted in memory and the data in it can be manipulated and updated independent of the database& When the use of this Data!et is finished1 changes can be made bac0 to the central database for updating& #he data in Data!et can be loaded from any valid data source li0e Microsoft !?9 server database1 an Oracle database or from a Microsoft Access database& Data Provider #he Data "rovider is responsible for providing and maintaining the connection to the database& A Data"rovider is a set of related components that wor0 together to provide data in an efficient and performance driven manner& #he &5,# <ramewor0 currently comes with two Data"roviders$ the !?9 Data "rovider which is designed only to wor0 with Microsoft8s !?9 !erver /&= or later and the OleDb Data"rovider which allows us to connect to other types of databases li0e Access and Oracle& ,ach Data"rovider consists of the following component classes$ #he 'onnection object which provides a connection to the #he 'ommand object which is used to e-ecute a #he Data;eader object which provides a forward-only1 read only1 recordset #he DataAdapter object which populates a disconnected Data!et with performs update database command connected data and

Data access with ADO&5,# can be summari@ed as follows$ A connection object establishes the connection for the application with the database& #he command object provides direct e-ecution of the command to the database& f the command returns more than a single value1 the command object returns a Data;eader to provide the data& Alternatively1 the DataAdapter can be used to fill the

Dataset object& #he database can be updated using the command object or the DataAdapter&

Component classes that ma e up the Data Providers The Connection O!"ect #he 'onnection object creates the connection to the database& Microsoft 3isual !tudio &5,# provides two types of 'onnection classes$ the !2l'onnection object1 which is designed specifically to connect to Microsoft !?9 !erver /&= or later1 and the OleDb'onnection object1 which can provide connections to a wide range of database types li0e Microsoft Access and Oracle& #he 'onnection object contains all of the information re2uired to open a connection to the database& The Command O!"ect

#he 'ommand object is represented by two corresponding classes$ !2l'ommand and OleDb'ommand& 'ommand objects are used to e-ecute commands to a database across a data connection& #he 'ommand objects can be used to e-ecute stored procedures on the database1 !?9 commands1 or return complete tables directly& 'ommand objects provide three methods that are used to e-ecute commands on the database$ ,-ecute5on?uery$ ,-ecutes commands that have no return values such as 5!,;#1 >"DA#, or D,9,#, ,-ecute!calar$ ;eturns a single value from a database 2uery ,-ecute;eader$ ;eturns a result set by way of a Data;eader object

The Data#eader O!"ect #he Data;eader object provides a forward-only1 read-only1 connected stream recordset from a database& >nli0e other components of the Data "rovider1 Data;eader objects cannot be directly instantiated& ;ather1 the Data;eader is returned as the result of the 'ommand object8s ,-ecute;eader method& #he !2l'ommand&,-ecute;eader method returns a !2lData;eader object1 and the OleDb'ommand&,-ecute;eader method returns an OleDbData;eader object& #he Data;eader can provide rows of data directly to application logic when you do not need to 0eep the data cached in memory& 4ecause only one row is in memory at a time1 the Data;eader provides the lowest overhead in terms of system performance but re2uires the e-clusive use of an open 'onnection object for the lifetime of the Data;eader& The DataAdapter O!"ect #he DataAdapter is the class at the core of ADO &5,#8s disconnected data access& t is essentially the middleman facilitating all communication between the database and a Data!et& #he DataAdapter is used either to fill a Data#able or Data!et with data from the database with it8s <ill method& After the memory-resident data has been manipulated1 the DataAdapter can commit the changes to the database by calling the >pdate method& #he DataAdapter provides four properties that represent database commands$ !elect'ommand nsert'ommand Delete'ommand >pdate'ommand When the >pdate method is called1 changes in the Data!et are copied bac0 to the database and the appropriate nsert'ommand1 Delete'ommand1 or >pdate'ommand is e-ecuted&

Das könnte Ihnen auch gefallen