Você está na página 1de 22

|  

| 

Lecture No:30
— 
| 
! Net is an object oriented framework
that allows you to interact with database
systems
! NET is an object-oriented set of
libraries that allows you to interact with
data sources ommonly, the data source
is a database, but it could also be a text
file, an Excel spreadsheet, or an XML file
Traditional architecure
! e usually interact with database systems
through SQL queries or stored procedures In
traditional data access components, you made a
connection to the database system and then
interacted with it through SQL queries using the
connectionThe application stays connected to
the  system even when it is not using 
services This commonly wastesvaluable and
expensive database resources, as most of the
time applications only query and view the
persistentdata
NET
! The best thing about Net is that it is extremely
flexible and efficient
! Net also introduces the concept of a disconnected
dataarchitecture
! Net solves this problem by managing a local buffer
of persistent data called a data set
! our application automatically connects to the database
server when it needs to run a query and then
disconnects immediately after getting the result back and
storing it in the dataset
! This design of Net is called a disconnected data
architecture and is very much similar to the
connectionless services of HTTP on the internet
! It should be noted that Net also provides
connection oriented traditional data access services
Traditional ata ccess
rchitecture
! onnect to 
! Pass query1 and access data from 
! fter some time Pass query2 and access
from 
! fter some time Pass query3 and access
from 
! isconnect 
Net isconnected ata
ccess rchitecture
! onnect to 
! Pass query1 and access data from 
! isconnect 
! fter some time, onnect to , Pass
query2 and access from , isconnect

! fter some time, onnect to , Pass
query2 and access from , isconnect

Net isconnected ata
ccess rchitecture
! nother important aspect of disconnected
architecture is that it maintains a local repository
of data in the dataset object The dataset object
stores the tables, their relationship and their
different constraints The user can perform
operations like update, insert and delete on this
dataset locally, and the changes made to the
dataset are applied to the actual database as a
batch when needed This greatly reduces
network traffic and results in better performance
dvantages and isadvantages of
NET
! dvantages:
! It is disconnected data architecture Here data is
retrieved and cached on your local machine
The biggest advantage here is reduced burden
on the database server and helps our
application to scale well
! isadvantages:
! cursor is a database element that controls
record navigation, the ability to update data, and
the visibility of changes made to the database by
other users NET does not have an
inherent cursor object
iscriminate  and Net

! s in classic  we had client and server


side cursors they are no more present in
NET
! Note it's a disconnected model so they are no
more applicable
! Locking is not supported due to disconnected
model
! ll data persist in XML as compared to classic
 where data persisted in inary format
also
         
     

!    This contains the basic objects used for accessing


and storing relational data, such as ataSet,ataTable, and
ataRelation Each of these is independent of the type of data
source and the way we connect to it

!  |  |It contains the objects that we use to


connect to a data source via an LE- provider, such as
lebonnection, lebommand, etc

!  |   This contains the objects that we use to


connect to a data source via the Tabular ata Stream (TS)
interface of Microsoft SQL Server (only)

!   This ontains the basic objects required to create,


read, store, write, and manipulate XML documents according to
3 recommendations
|   | 
! ll generic classes for data access are contained in
theSystemata namespace
! ¢ 

! |   The ataSet is a local buffer of tables or a
collection of disconnected record sets
! |   ! ataTable is used to contain data in
tabular form using rows and columns
! |  " Represents a single record or row in a
ataTable
! |   Represents a column or field of a
ataTable
! |  "   Represents the relationship between
different tables in a data set
!     Represents the constraints or limitations
that apply to a particular field or column
| |  #
! | |  #  !         
  

#  |  |

 ata Provider dbcata Sources with an  interface


Normally older data bases

leb ata Provider Sources that expose an leb interface, ie ccess
or Excel
racle ata Provider For racle atabases

SQL ata Provider For interacting with Microsoft SQL Server

orland ata Provider Generic access to many databases such as Interbase,


SQL Server, IM 2, and racle
The Managed providers that are
currently available with NET
! SQL server managed provider
! LE  managed provider
!  managed provider
! managed provider for R LE
NET L SSES
! Net also contains some database specific classes This means
that different database system providers may provide classes (or
drivers) optimized for their particular database system
! Microsoft itself has provided the specialized and optimized classes
for their SQL server database system The name of these classes
start with 'Sqlµ and are contained in the SystemataSqllient
namespace
! Similarly, racle has also provides its classes (drivers) optimized for
the racle  System
! Microsoft has also provided the general classes which can connect
your application to any LE supported database server The name
of these classes start with 'leb' and these are contained in the
Systemataleb namespace
! In fact, you can use leb classes to connect to SQL server or
racle database; using the database specific classes generally
provides optimized performance
NET L SSES
!   $ |! 
Represents a connection to the database
system
!  $ |!  Represents
SQL query
! |   $ |!|    class
that connects to the database system, fetches
the record and fills the dataset
! |  " $ |!|  "  stream
that reads data from the database in a
connected design
! #  $ |!#   Represents a
parameter to a stored procedure
|  !%
! onnection object
! ommand object
! ataReader object
! ataSet object
! ata dapter object
    !%
! To interact with a database, you must
have a connection to it The connection
helps identify the database server, the
database name, user name, password,
and other parameters that are required for
connecting to the data base connection
object is used by command objects so
they will know which database to execute
the command on
   !%
! he process of interacting with a database means
that you must specify the actions you want to
occur This is done with a command
object ou use a command object to send SQL
statements to the database command object
uses a connection object to figure out which
database to communicate with ou can use a
command object alone, to execute a command
directly, or assign a reference to a command
object to an Sqlata dapter, which holds a set
of commands that work on a group of data as
described below
 |  "  !%
! Many data operations require that you only get a
stream of data for reading The data reader
object allows you to obtain the results of a
SELET statement from a command object For
performance reasons, the data returned from a
data reader is a fast forward-only stream of
data This means that you can only pull the data
from the stream in a sequential manner This is
good for speed, but if you need to manipulate
data, then a ataSet is a better object to work
with
 |   !%
! ataSet objects are in-memory representations
of data They contain multiple atatable objects,
which contain columns and rows, just like normal
database tables ou can even define relations
between tables to create parent-child
relationships The ataSet is specifically
designed to help manage data in memory and to
support disconnected operations on data, when
such a scenario make sense The ataSet is an
object that is used by all of the ata Providers,
which is why it does not have a ata Provider
specific prefix
 |    !%
! Sometimes the data you work with is primarily read-only and you
rarely need to make changes to the underlying data source Some
situations also call for caching data in memory to minimize the
number of database calls for data that does not change
! The data adapter makes it easy for you to accomplish these things
by helping to manage data in a disconnected mode
! The data adapter fills a ataSet object when reading the data and
writes in a single batch when persisting changes back to the
database
! data adapter contains a reference to the connection object and
opens and closes the connection automatically when reading from
or writing to the database
! dditionally, the data adapter contains command object references
for SELET, INSERT, UP TE, and ELETE operations on the
data ou will have a data adapter defined for each table in a
ataSet and it will take care of all communication with the database
for you ll you need to do is tell the data adapter when to load from
or write to the database

Você também pode gostar