I am learning ADO.Net. I read this line:-
DataReader is "connected" approach and dataset is "disconnected" approach
From this sentence I have reached to this conclusion that in data reader we need to establish the connection to the database while in dataset we do not need to establish the connection to the data base.
But how without establishing the connection one can access data.I know I am not getting the exact meaning.
Please any one can tell me the exact meaning with example.
In classic ADO the
RecordSet
object could work both in connected and disconnected mode. In Ado.Net there are two separate types available to cater to each of these scenarios -IDataReader
andDataSet
Connected Mode: remains connected to the underlying data source while traversing in a forward-only streams of result sets.
Disconnected Mode: the resultset retrieved is kept in memory and the connection to the DB is no longer needed for traversal.
This MSDN article further compares the two objects and discusses their individual merits a lot better than I will be able to explain here.
Connected Architecture : For Every request , Hit the Database , Fetch the DATA and bring Back. you can perform only Read Operation.Connection should be always OPEN.Uses Data Reader
Dis Connected Architecture : Fetch the Entire Data at once and now perform whatever operation you want to perform. Isert / Update / Delete. No need for the connection to be always OPEN.Uses Data Set , Data Adapter
Connected architecture: In connected model we can connect any application to database and stays connected to the database system even when it is not using any database operations. For this architecture, we use
Connection
,Command
andDataReader
.Disconnected architecture: In disconnected model we connect any application to database until we call the close method. In this architecture we use
DataSet
andDataAdapter
.Think DataSet as in memory database, it contains DataTables and contain tables data (all or subset of data based on Select query) and even maintain relations among tables. On the DataSet you can perform update/delete operations, it will be synched to database through DataAdapter object. so to display data it does not need to be connected to database All time as DataReader, which needs to be connected to database whenever you want to display data.
Disconnected = Make Connection , Fetch Data , Close Connection
Connected = Make Connection , Keep Connection alive , Close Connection when close is called.
For more information , please see the link on MSDN
The ADO.net architecture, in which connection must be kept open till the end to retrieve and access data from database is called as connected architecture. Connected architecture is built on the these types -
connection
,command
,datareader
The ADO.net architecture, in which connection will be kept open only till the data retrieved from database, and later can be accessed even when connection to database is closed is called as disconnected architecture. Disconnected architecture of ADO.net is built on these types -
connection
,dataadapter
,commandbuilder
anddataset
anddataview
.