7

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.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Suri
  • 518
  • 2
  • 6
  • 20
  • Take a look http://stackoverflow.com/questions/1083193/whats-better-dataset-or-datareader and http://sadi02.wordpress.com/2008/06/30/adonet-datareaderconnected-and-datasetdisconnected-in-c-net-with-examples/ – Soner Gönül Mar 22 '13 at 06:59
  • DataSet is an outdated approach. Take a look at Entity Framework and/or other OR/M like NHibernate. – Matías Fidemraizer Mar 22 '13 at 07:00

6 Answers6

10

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

TalentTuner
  • 17,262
  • 5
  • 38
  • 63
  • thanks bro.can you please give some real example to clarify me – Suri Mar 22 '13 at 07:01
  • @Sourabh I have gone through the link.I have some confusion regarding OLEDB and ODBC.What are these?I am not getting it from the link and no graphical representation is given. – Suri Mar 22 '13 at 11:35
  • @Sourabh In ADO .Net data is stored at client side or only html is rendered to the client – Suri Oct 28 '13 at 10:42
3

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 and dataset and dataview.

Deepak Raj
  • 730
  • 2
  • 9
  • 26
1

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.

Adeel
  • 19,075
  • 4
  • 46
  • 60
  • why in the case of Datareader connection to the database is required all the time – Suri Mar 22 '13 at 07:05
  • Because when you are reading a record e.g. reader.Read(), it directly reads from the Database, so connection is required. – Adeel Mar 22 '13 at 07:09
  • @ Adee are you sure.I think after executing the ExecuteReader() the data is cached to the local memory in windows and when reader.Read() is executed it reads from here not directly from Database. – Suri Mar 23 '13 at 11:39
0

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 and DataSet

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.

NoviceProgrammer
  • 3,347
  • 1
  • 22
  • 32
0

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

-2

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 and DataReader.

Disconnected architecture: In disconnected model we connect any application to database until we call the close method. In this architecture we use DataSet and DataAdapter.

Peter Duniho
  • 68,759
  • 7
  • 102
  • 136