ADO.Net - Active X Data Object
What is ADO.Net ?
It is a set of computer software components that programmers can use to access data and data services. It is commonly used by programmers to access and modify data stored in relational data base systems, though it can also access data in non-relational sources.
Why ADO.Net?
ADO.Net maintains a disconnected database access model, ie. when the application request for any for service, then the connection is opened to serve the request, and closed as soon as the request is completed. By keeping the connection opened only for a minimum time, it conserves system resources, and ensures maximum security and has less impact on system performance. When ADO.Net interacts with DB, it converts all the data into XML format for DB related operations and makes it more efficient.
ADO.Net data Architecture:
Data access on ADO.Net requires 2 components : Dataset and Data Provider.
A connection object creates a connection to the data base. Command object enables the direct execution of the command to the database. When the command returns more than a single value, then it returns a data reader with data binded to it. Can also use data adapter to fill the data set.
ADO.Net Components:
.Net Data Provider:
Data provider components are explicitly designed for data manipulation and fast and forward only, read only access to data. The components of Data Provider are as follows:
1. Connection: object provides connection to the database.
2. Command: object enables access to database commands to return data, modify data, run stored procedure, send or retrieve parameter info.
3. Data Reader: object provides high performance stream of data from the data source. Provides a forward only, read only connected record set.
4. Data Adapter: provides bridge between data set and the data source.It populates a disconnected data set with data and performs update.
Data Set:
It is a disconnected in memory representation of data. Can be considered as a local copy of particular data.
Components of Data Provider:
Connection Object:
- It creates the connection to the database.
- Provides 2 types of connection classes:
1. SqlConnection class : Designed specially for SQL Server.
2. OleDbConnection object: can provide connection to a wide range of servers like Access, Oracle.
- Contains all the information regarding the connection to the data base.
Command Object:
- Represented by two commands SqlCommand and OleDbCommand
- Used to execute the commands/ stored procedures to the data base. And returns data back.
- Provides 3 methods to execute the command
1. ExecuteNonQurery: Executes query which doesn't have any return value - Ex. Insert, Update, Delete
2. ExecuteScalar: Returns a single value from the database.
3. ExecuteReader: Returns a resultant set by the way of DataReader.
DataReader Object:
- Provides a forward - only, read - only, connected stream record set from the database.
- Cannot be directly instantiated. Returned as the result of ExecuteReader method of Command object.
- Provides rows of data directly to the application logic, when you do not need to keep in memory cache.
- As only one row is in memory at a time, it provides lowest overhead in system performance, but requires exclusive use of open connection till the life time of the data reader.
DataAdapter Object:
- Core of ADO.Net disconnected data access.
- middleman in communicating between the data set and the database.
- Used to fill either the data set or the data table.
- Can also be used to commit the changes.
- Provides 4 properties:
SelectCommand, InsertCommand , DeleteCommand, UpdateCommand
- When UpdateCommand is called, the respective changes are copied to the database and the appropriate InsertCommand, DeleteCommand, UpdateCommand are executed.
No comments:
Post a Comment