Seminar in Software Design : Microsoft ADO.NET
ADO .NET
Lecturer

Andrei Otcheretianski
Tomer Rothschild

Presentation

ADO .NET

Abstract

Almost every application handles data, whether it's in the form of a relational database, text file, or spreadsheet.
Since the data is usually separated from the client application, you need to somehow fetch and bring it to your application before it can be displayed to users, manipulated and saved back to the data source.

ADO.NET (ActiveX Data Objects) is the primary relational data access model for Microsoft .NET-based applications.
ADO.NET is designed around an architecture that uses connections sparingly. Applications are connected to the database only long enough to fetch or update the data.
Another tendency of ADO.NET was to supply a generic inteface while at the same time connecting to the data sources directly.
This lead to whole new architecture of the data access objects - not just an adaptation of the former ADO into the .NET framework.

These two Orientations are achieved by it's two main constructs:
  • DataSet
    The DataSet object is a memory resident representation of data that provides a consistent relational programming model regardless of the data source.
    Since you are not streaming between your application and your database, you are saving a considerable amount of network traffic thereby speeding up the displaying of data to the user.
    The DataSet is, by design, disconnected at all times. Because it holds no persistent connection to outside resources, it is ideal for packaging, exchanging, caching, persisting, and loading data.
  • Data Providers
    The data Providers are the ADO.NET objects that interact with the data sources.
    ADO.NET was designed from the beginning to allow the provider writers the space to support database-specific features.
    The archetecture achieved by this model is much cleaner and faster - without unneeded layers between the client application and the data source.

ADO.NET is also endowed with extensive support for XML.
Indeed, The entire .NET framework is built upon and relies upon XML and related technologies. The ADO.NET DataSet is particularly dependent on XML. Every piece of data in the DataSet object may be transported in or out via XML. As we shall see in the demo, this abillity is very usefull in an XML reliant enviorement such as web services. In addition, the DataSet's internal data structures may be defined by XML schemas as showen in the demo.

Pros & Cons

Pros:
  • Performance - mostly gained by the specific providers.
  • Managed Classes - All the benefits that come with the CLR.
  • XML Support (and Reliance) - As mentioned above, the extensive support of XML is an integral part of ADO.NET.
  • Disconnected Operation Model - Enables greater scalabillity.

Cons:
  • Only four Managed Data Providers (so far) - The goal of establishing direct connections via native data provider is somewhat stuck. Thus, the performance is boosted only when running against SQL Server and Oracle - which have specific data providers.
  • Managed-Only Access - Cannot utilize the ADO.NET architecture from anything but managed code. This means that there is no COM interoperability allowed for ADO.NET

References

ADO.NET MSDN homepage
Overview of ADO.NET - MSDN
A descriptive overview of ADO.NET
A thorough article of the main features of ADO.NET

Demo
Overview

The demos demonstrate the following issues:

  1. Relating Tables in the DataSet and exporting & importing the data in XML format:
    In this demo we can learn how to load the data from the data source and process it locally using DataSet. Moreover, we understand the role of the XML schema in defining the structure of the DataSet object. The application loads a dataset with two tables from the Northwind DB which comes with MS SQL Server 2000. We add the relation based on a foreign key between the tables. There is also an option to export/import data from the dataset into XML format.



  2. Remote DB Access Through DataSet
    The second demo is essentially a web form for regestering the arrival times of the students of the seminar.



    The demo shows how to utilize the disconnected model to the fullest. The scenario illustrated by the demo is such that the web page running the form doesn't have an authorization to interact with the underlying DB directly. Instead, it communicates with a web service, and remotely retrieves and updates the data in the DB using the web service's exposed methods. All the data manipulation is done solely by the DataSet object.




Files

Download Demos' source files

Extract this zip file anywhere on your computer.
It contains 5 following directories:
  • Ado_Net_Demo1 - This is our first demo
  • Ado_Web_Client - This is the client Web application (second demo)
  • Ado_Web_Client sol - This folder contains the solution file
  • Ado_Web_Service - This is the WebService which actually talks to the SQL Server
  • Ado_Web_Service sol - This is the WebService's solution file

Demo Installation Instructions

Prior to installing the demos make sure that Visual Studio, SQL Server & IIS are properly installed and running.

The ADO.NET is part of the .NET which in turn, ships with the Visual Studio. You may also download the .NET Framework & SDK for free from Microsoft However, our explanations regard to using Visual Studio.

In addition, verify that your security configurations are set to Authentication: SQL Server and Windows. The easiest way to do it is through the Enterprise Manager as shown in the following figure.
One last thing, the demos assume that the password for "sa" (system admin) is left blank. If this is not the case, you may either change the connection strings or the "sa" password.




Activate the first demo by following these steps:
  1. Insure that your SQL server is properly running.
  2. Open the solution file from the Ado_Net_Demo1 folder with Visual Studio and run it.


Activate the second demo by following these steps:
  1. Create a new DB in the Enterprise Manager
    • Create a new Database by right clicking on "Databases" on the left tab and choosing new database.
    • Call the new database "AdoDemoDb".
    • Click on the Tables in the created "AdoDemoDb" folder.
    • Right click on the right tab and choose "new table".
    • Fill the columns according to the following schema:
      name, char, 30
      lectureTopic, char, 30
      arrivalTime, datetime, 8
    • Click "save" and call the table "ssdTable".



  2. Set up virtual directories in the IIS
    • Right click on my computer and choose manage.
    • On the left tab right Click on "Default website" under "Services and Applications"->"Internet Information Services"->"Web Sites" and choose "new ..."->"Virtual Directory".
    • In the alias field write "Ado_Web_Client".
    • In the directory field give the path to the extracted "Ado_Web_Client" folder.
    • Perform the same steps for "Ado_Web_Service".



  3. Open the solution files located in "Ado_Web_Service sol" & "Ado_Web_Client sol" in Visual Studio.

Features & Comments


  • DataSet import/export Demo:
    • It should be noted that when we export the DataSet into XML file, we don't save the internal structure of the DataSet. It is impossible to understand from the exported XML file that there was any relation between the tables. Since we still want to keep the structure of the DataSet we save and load it's schema explicitly. The schema file can be found in the same directory with the executable.
    • One of the most important features that the schemas grant is creating typed DataSets, i.e. binding the schema in design time, which customizes our Dataset. Here you can learn more about this feature.
  • Arrival Times Demo:
    • The transport of the DataSet between the web client and the web service, though invisible to the programmer, is achieved through automatic XML serialization.
    • As can be easily observed, the web service method "updateArrivalTimes" has sql statements for update and delete as well as insert.
      It's important to note that this method consolidates any changes made to the underlying DB - not just added rows.
      Indeed, this method may be used as it is, by a more "sophisticated" client that also removes or updates the existing rows.
    • Another notable feature in the demo is that of the Web client, which has DBMS independent code.
      This is achieved because all the data access is made through the DataSet object, without ever establishing a connection explicitly.
Enjoy your disconnected voyage through the world of ADO.NET!