By Chris Pascucci and FLF

Slides:



Advertisements
Similar presentations
Database Connections with ASP.Net
Advertisements

Lecture 14 A new Introduction to Databases: DB Review & ADO.NET Models – Connected and Disconnected By Chris Pascucci and FLF.
Chapter 10 ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a programming interface to access data in a database.
Introduction to Database Processing with ADO.NET.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 13-1 COS 346 Day 25.
1 ADO.NET. 2.NET Framework Data Namespaces System.Data –Base set of classes and interfaces for ADO.NET System.Data.Common –Classes shared by the.NET Data.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
Chapter 12 Database Connectivity with ASP.NET JavaScript, Third Edition.
CSC 2720 Building Web Applications Database and SQL.
Objective In this session we will discuss about : What is ADO. NET ?
Overview of Database Access in.Net Josh Bowen CIS 764-FS2008.
Introduction to Databases: DB Review & ADO.NET Models – Connected and Disconnected.
Chapter 8 Binding Data to Web Controls. ASP.NET 2.0, Third Edition2.
ADO.NET – part II August 2004 [ Marmagna Desai]. CONTENTS ADO vs ADO.NET ADO.NET – Managed providers Connecting to Database SqlConnection Selecting Database.
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
ADO.NET A2 Teacher Up skilling LECTURE 3. What’s to come today? ADO.NET What is ADO.NET? ADO.NET Objects SqlConnection SqlCommand SqlDataReader DataSet.
FEN Data connection DataReader DataSet Bonus info: Concurrency and Database Transactions Embedded SQL.
Web Services Week 8 Aims: –Using web services as front ends to databases Objectives: –Review of relational databases –Connecting to and querying databases.
A Simple Introduction. What is ADO.net? First the word ADO stands for ActiveX Data Objects And it is an integral part of.Net Framework of Microsoft hence.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Needs for Accessing Database To make your web site more dynamic and maintainable, you can display information on your web pages that are retrieved from.
Databases and Data Access  Introduction to ADO.NET  ADO.NET objects  ADP.NET namespaces  Differences between ADO and ADO.NET.
1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006.
Chapter 3 Introduction to ADO.NET 3.1 The ADO and ADO.NET ActiveX Data Object (ADO) is developed based on Object Linking and Embedding (OLE) and Component.
Database, SQL, and ADO.NET- Part 1 Session 11 Mata kuliah: M0874 – Programming II Tahun: 2010.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with Disconnected Data The DataSet and SqlDataAdapter ADO.NET - Lesson.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL ADO.Net Basics Ruwan Wijesinghe Trainer.
Objectives In this lesson, you will learn to: *Identify the need for ADO.NET *Identify the features of ADO.NET *Identify the components of the ADO.NET.
10/26/20151 Chapter 3 Introduction to ADO.NET In this chapter, you will: Learn the basic classes in ADO.NET and its architecture Learn the different ADO.NET.
ASP.NET Rina Zviel-Girshin Lecture 5
Module 9: Accessing Relational Data Using Microsoft Visual Studio.NET.
Module 7: Accessing Data by Using ADO.NET
Christopher M. Pascucci.NET Programming: Databases & ADO.NET.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Introduction to ADO.NET ADO.NET - Lesson 01  Training time: 10 minutes  Author:
Object Oriented Software Development 10. Persistent Storage.
Presented by Joseph J. Sarna Jr. JJS Systems, LLC
ADO.NET. ADO.NET is a new, improved, and greatly expanded version of ADO that was developed for the Microsoft.NET initiative It incorporates all of the.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
ADO.NET connections1 Connecting to SQL Server and Oracle.
 It is the primary data access model for.Net applications  Next version of ADO  Can be divided into two parts ◦ Providers ◦ DataSets  Resides in System.Data.
The Problems HTTP is disconnected So many database vendors Create a simple consistent versatile interface on the data Look at ADO.NET classes OleDb SQL.
Mauricio Featherman, Ph.D. Washington St. University
Introduction to ADO.Net and VS Database Tools and Data Binding ISYS 350.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
HNDIT Rapid Application Development
2314 – Programming Language Concepts Introduction to ADO.NET.
Database Connectivity with ASP.NET. 2 Introduction Web pages commonly used to: –Gather information stored on a Web server database Most server-side scripting.
Module 4 Introduction ADO.NET.
Introduction Because database applications today reside in a complicated environment, various standards have been developed for accessing database servers.
Module 2: Using ADO.NET to Access Data. Overview ADO.NET Architecture Creating an Application That Uses ADO.NET to Access Data Changing Database Records.
1 A Very Brief Introduction to Relational Databases.
Data Access. ADO.NET ADO.NET is the primary library for building database solutions within the.NET Framework. ADO.NET does not replace ADO. ADO and OLEDB.
ADO .NET from. ADO .NET from “ADO .Net” Evolution/History of ADO.NET MICROSOFT .NET “ADO .Net” Evolution/History of ADO.NET History: Most applications.
.NET Data Access and Manipulation
Integrating Data Lesson 6.
ASP.NET Programming with C# and SQL Server First Edition
Introduction to ADO.NET
Accessing Databases using Ado.net
Introduction to Database Processing with ADO.NET
Introduction to Database Processing with ADO.NET
ADO.NET Framework.
Lecture 6 VB.Net SQL Server.
By Chris Pascucci and FLF
VB.NET Using Database.
Tonga Institute of Higher Education
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Chapter 10 ADO.
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
Presentation transcript:

By Chris Pascucci and FLF Lecture 14 C new Introduction to Databases - DB Processing: The Disconnected Model (Using DataAdapters, DataSets, and DataTables) By Chris Pascucci and FLF

The Disconnected Architecture – Data Sets ADO.NET provides classes that are used to create applications that utilize a database. You can create instances of these classes and use them in your application to manage and use database connections. To use these classes in the .NET Framework you must import the namespace System.Data that contains all these useful classes. When working in the disconnected mode the data retrieved from a database and utilized by your program is stored in a DataSet. The DataSet contains one or more DataTables. Data in the DataSet is independent of the database that was used to retrieve it. A data set can contain the result of multiple queries The connection to the database is typically closed after data is retrieved. The connection is opened again when it’s needed.

ADO.NET – The Data Adapter Manages the exchange of data between the DataSet and a database. It issues an SQL Command (Select, Insert, Update or Delete) that is stored in the Command object. The Command object uses a Connection object to connect to the database and retrieve or update the data. The data is transferred back to the DataAdapter, which then stores it in a DataSet that can be used by the application. Note carefully – everything we manipulate is an object

ADO.NET Explained (skip this slide)

Data Adapters - how the process works

ADO.NET Explained (skip this slide) The DataSet Object Model:

ADO.NET Explained (skip) The DataSet Object Model:

ADO.NET Explained An ADO.NET DataProvider connects to a data source such as SQL Server, Oracle, or an OLE DB data source, and provides a way to execute commands against that data source. The ADO.NET classes responsible for working directly with a database are provided by the NET DataProviders: The .NET Framework includes data providers for SQL Server, Oracle, OLE DB, ODBC, etc… The Data Providers included in the .NET Framework contain the same objects, although their names and some of their properties and methods are different. For example, the SQL Server version of a database connection is the SqlConnection, while the OLE DB version is an OleDbConnection. ODBC = Open Database Connectivity (Relational/Procedural/First Abstract Model) OLE = Object Linking and Embedding (OO Based – Microsoft)

Connection (Review 1) The connection component is used to establish a connection to a database and manage communications between the data source and your program. Use the appropriate connection class. OleDbConnection, SqlConnection, OracleConnection, … Example:

Connection (Review 2) The connection string is a simple string that is used to create a connection object. The connection string contains key-value pairs The assignment operator (=) is used to separate the key and the value. A semi-colon (;) is used to separate each key-value pair. The connection string is different for each DataProvider.

Connection (Review 3)

DataAdapter Executes commands against a database and manages the transfer of information from the database to the DataSet. Use the appropriate DataAdapter class. OleDbDataAdapter, SqlDataAdapter, OracleDataAdapter, … Example: Note similarity with ExecuteQuery in connected mode

Using a Command with a DataAdapter The command component is used to take an SQL command you provide, prepare it for transport through the connection object, and for processing in the DBMS. For our purposes, this is optional and can be easily replaced with a simple string. The command object is created by passing it a simple string with SQL statements, and the connection object. Example:

Commands (Review)

ADO.NET Programming Example: Dim strSQL As String Dim strConnection As String Dim objDataSet As New DataSet() Dim objAdapter As SqlDataAdapter Dim objConnection As SqlConnection strConnection = "server=dwarf.cis.temple.edu;Database=4376nn;” & _ “User id=4376nn;Password=yourpassword“ strSQL = "SELECT * FROM Product“ objConnection = New SqlConnection(strConnection) objAdapter = New SqlDataAdapter(strSQL, objConnection) objAdapter.Fill(objDataSet) DataSet used to hold data retrieved from the database. SQL Server DataProviders for working with an SQL Server data source. Connection object used to establish a connection. DataAdapter object used to manage the flow of data from the data source to the DataSet. Fills the DataSet object with data retrieved from the database.

ADO.NET All elements of a database, tables, rows (set of values that make up a record), columns (database fields), and individual cells (actual field values) are all represented as abstractions (classes) in .NET. Basically, every table, row, and column are represented as instances of these abstractions (classes) that are part of the ADO.NET support structure.

Disconnected vs. Connected The major advantage of the disconnected approach is that it improves system performance Uses less resources for maintaining connections when working with a data source. Work is done on local data: DataSets, DataTables, etc However, there is a disadvantage to this approach that occurs when two or more users try to update the same row of a table, which is called a concurrency problem.

Disconnected vs. Connected ADO.NET contains two different approaches to work with data in a database: Connected Data Architecture and the Disconnected Data Architecture. Connected Data Architecture: Represents the objects that insist on having an open connection available for them to work and interact with the data source. ADO.NET provides classes to communicate directly with a data source. Disconnected Data Architecture: Represents the objects that open and close a connection to the data source as needed. Your application works with data that was copied from the data source. Any changes made to the “copied” data in the Dataset will be later reconciled with the data source. Connected applications alone don't fulfill the demands of today’s distributed applications. Improved performance, more efficient and more complex than the connected approach.

Concurrency Issues An old time problem when dealing with shared resources such as memory, files, DBs etc Occurs when multiple users try to access the same resource such as a row in a database table Not a problem if all users are reading the resource Becomes a problem if one or more are writing Locking mechanisms need to be implemented to ensure the integrity of the resource

Disconnected vs. Connected Modes When using the disconnected mode of DB access concurrency problems occur because once data is retrieved by User A from the database, the connection is dropped. Now User B has can access the DB There are two ways that ADO.NET can handle concurrency problems: Optimistic Concurrency – The program checks to see if there has been a change to the row since it was retrieved. If it has, the update or deletion will be refused and a concurrency exception will be thrown that your program must handle. “Last In Wins” – Since no checking is done, the row that was updated by the last user will overwrite changes made to the row by the previous user. Another way to avoid concurrency problems is to retrieve and update only one row at a time.

Steps to Working with ADO.NET (disconnected) First, a database connection is established Then the database is opened SQL commands are sent over the open connection ADO.NET builds an in-memory representation of the returned data from any SELECT command and changes are made to this representation When processing is complete, the database connection is closed It is suggested that you use the Open and Close methods to explicitly open and close your connections. In this way, you keep your connections open only as long as needed to complete the required processing

Processing database elements All elements of a data base, tables (entities), rows (sets of values), columns (database fields), and individual cells (database values) are represented as abstractions in .NET In other words, every table, row, and column are represented as instances of the abstractions (classes) that are part of the ADO.NET support structure

How Do the Pieces Fit Together? Study the code example from Chris Pascucci first (see Lecture Set 14 C Ex) Then study the code sample provided by your lab assistant (Jessica Clark) at the end of the Client-Server Word document (also look at the starter code for the Final Project, Part III – ref . HW #12)

An Underlying Framework – The Connection Keeping a mental picture of this process in your head is important It all begins with the connection Already visited this idea for files. Now we revisit it again for databases Remember … In your programs, you manipulate objects using methods belonging to the class that defines the type of the object The class (an abstract data type) is an abstraction (model) of the object being manipulated

The Object Framework (drawing/files) Recall … We must have a class to model the entity to be manipulated (the surface to be drawn on) The class is said to define an “abstract data type” We can then create objects (instances of the class we just created) Next comes the tricky part … We now have to connect that object to the actual entity to be drawn on OR Have to connect a stream to a sequential file

The Object Framework 2 For databases, the object is an instance of a class that provides an abstract view of the database including an abstraction of database tables, rows, and columns All of these database features are modeled using ADO.NET classes So we program against elements of the ADO.NET classes without concern for the underlying structures

The Object Framework 3 – The Connection The actual, physical database to be manipulated The database abstraction (methods and data stores) that you program against (DB commands, internal datasets and data tables) The connection – via creation of a database connection object ‘Example - Connection to a Microsoft Access Database Dim myConnectionObj As New OleDbConnection(ConnectString) ‘Example - Connection to SQL Server Database Dim myConnectionSqlObj As New SqlConnection(SqlConnectString)

Remember … Why do this – what is this all about? The abstraction enables us to manipulate database objects in a uniform, consistent way, regardless of the DBMS (Access, MySQL, SQL Server, Oracle) The underlying DBMS is hidden under several layers of ADO.NET software which does all the work

Connection Strings – (disconnected mode) All we need to do is connect the program’s ADO.NET database object to the underlying database to be used ‘SQL Server Connection Dim SqlConnectString As String = _ "server=dwarf.cis.temple.edu;Database=fa06_c342132;” & _ "User id=fa06_c342132;Password=jimbo“ Dim myConnectionSql As New SqlConnection(SqlConnectString) ‘Access Connection Dim ConnectString As String = "provider=Microsoft.Jet.OLEDB.4.0;” _ “Data Source=c:\users1\dl\Inventory.mdb“ Dim myConnection As New OleDbConnection(ConnectString) Programmer layer – build commands (SELECT, INSERT, DELETE, and UPDATE) for execution against the database Logical layer – uses a DataAdapter to send commands from your software (across the data adapter) to the database getting back tables to be processed Physical layer – manages the actual (physical) execution of the commands on the database

ADO.NET (skip)

ADO.NET Terms Summary (Review) DataSet: Data in the Dataset is independent of the database that was used to retrieve it. DataAdapter: Manages the exchange of data between the Dataset and a database. Allowing a DataSet and DataTable to be filled from the data source and later reconciled with the data source. Connection: Connects to the data source. Command: Executes commands (SQL statements) against the data source. Data Providers: The ADO.NET classes responsible for working directly with a specific database. Data Reader Retrieves query results in a read-only, forward-only connected result set.

ADO.NET Resources Connection Strings: OleDbConnection Class: http://www.connectionstrings.com OleDbConnection Class: http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbconnection.aspx OleDbCommand Class: http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand.aspx OleDbDataAdapter Class: http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbdataadapter.aspx OleDbDataReader Class: http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbdatareader.aspx