why dataset in ado.net is disconnected

N

naruto2000x

I appereciate anyone's help with this.

i am really confused with idea of dataset in ado.net is disconnected.

if let say if we issue an update sql statement using data adapter and
dataset in that

Dim strSQL as string = "update customer set name = 'joe' where ID =
5"

Dim DA as new SQLDataAdapter(strSQL, SQLCONNECTIONOBJECT)
Dim ds AS new Dataset
DA.Fill(DS, "tablename")

the underlying Customer Table in my database is actually get updated.
So in what way DATASET is disconnected


Thanks for the help.

winnie

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
S

Sahil Malik

Winnie,

A little background first of "Why disconnected" --
--------------------------------------------------

In the modern internet driven world, under high demand applications, you
need to be able to support thousands of concurrent users on a server
application - all interacting with the database in a real-time mode. One
option was that each one of these users gets a dedicated connection -
however in most applications, the users spend a lot of time working on the
UI, or the business layer is crunching some numbers, it is a terrible waste
of resources for the database server to

a) Either maintain an open connection all the time.
b) Open and close physical connections at every request.

So connections are pooled in the time slices they are not being used. The
time slice in which a connection is pool-able is - when no one else is using
it - i.e. between the Open and Close calls of say a SqlConnection object.

So why is a dataset disconencted? To encourage you to connect as late as
possible and to encourage you to disconnect as soon as possible - for the
above scenarios. Not to mention other side benefits of easy serializability,
data bindability, inbuilt concurrency support etc.

To finally answer your question of "How is it disconnected" ---
---------------------------------------------------------------

"In what way is the dataset disconnected".

When you run SqlDataAdapter.Fill .. a dataset gets filled - at that point,
it is completely disjoint/disconnected from the database. You could save the
dataset to the disk and reboot the server. There is no connection between
the two anymore - however as you make changes to the dataset, it "remembers"
original values - and the "Update" function on SqlDataAdapter reconnects to
the database and takes intelligent decisions based upon the changes,
persists those changes - and closes the connection ----- All transparent to
you.

This is where the beauty of ADO.NET shines - it was a complicated
disconnected model - that is so easy to use that we have someone asking "Is
this really disconnected" - quite a compliment for the ADO.NET team IMHO.

This is explained better in my upcoming ADO.NET 2.0 book in chapters #4 and
#6. Or you can also pick up my ADO.NET 1.1 book and read thru that for a
good explanation on this.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
 
C

Cor Ligthert

Naruto,

Think about a PDA, than all becomes in my opinion much clearer beside all
technical database server arguments.

Cor
 
N

naruto2000x

Hi All,

Thanks for your help. i did a testing and finally understand what
you said Sahil. i monitor the sqlconnection object's State event.
after the call to the fill method, the state changes from "open" to
"close".
So this is what it means by the "disconnected" mode, the connection to
the underlying database is close, right after the call to the data
adpater's fill method is finished.

One more question, is it neccesary to use the Update method of the
data adapter to write the changes back to the database? what i mean
is that when we pass a sql UPDATE, INSERT, or DELETE statement to the
data adapter contructor follows by its fill method, the database will
automatially get updated based upon the sql statement that we pass
in.
So in what situation we will use update method?

thanks

winnie,

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
S

Sahil Malik

Winnie,

The Update method as you rightly identified is used to persist the dataset
changes back to the database. For simplistic cases it uses an object called
CommandBuilder to try and take default decisions for you. It iterates
through rowstates and persists those changes accordingly. Alternatively you
have the option and in most cases you should specify various commands on
UpdateCommand/InsertCommand/DeleteCommand properties of the data adapter.

Hope that clarifies a bit.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
 
W

W.G. Ryan eMVP

Naruto - if you don't call update, but have valid commands, you are
essentially in the same place as if you had a TV but didn't turn it on. In
many cases, you don't need to send changes back so you don't need to call
update. However unless you call it, there's no mechanism to tell the
dataadapter to send them back to the database.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top