Microsoft Visual C++ .NET Professional Projects - Premier Press
.pdf
PARTIVProfessional
Project – 3
This page intentionally left blank
Project 3
ADO.NET in
Managed C++
Project 3 Overview
Project 2 introduced you to programming in Managed C++. This project introduces you to the data access model ADO.NET. ADO.NET is an improved version of ADO and is the data access model used to design all database-centric applications that are intended to run in the .NET Framework.
In this project, you will create the banking application, which you earlier created using ODBC and MFC. The main highlight of this project is that it illustrates the implementation of ADO.NET in a Managed C++ application.
In the present scenario, all applications access data in some form or other. In case of desktop applications that work on standalone computers, accessing data is quite easy because the data is stored locally. Such applications require less programming effort for data access. On the other hand, data access in the case of distributed applications is more difficult because distributed applications deal with remote data sources that might be in different data formats or are stored in dif-
ferent locations.
In order to build data management functionality into applications, various data access techniques are used. The data access technique to be used for an application is decided keeping in mind the data access requirements of the application. A data access technique should be easy to program and deploy. The technique should also provide good performance and should be able to handle concurrent user connections without having an adverse effect on the system performance.
To begin with, the chapter gives you an overview of the evolution of various data access techniques. Later, you will be introduced to the ADO.NET architecture.
Data Access Techniques – An Overview
At present, most information exists in varied types of files, such as indexed sequential files, e-mail, productivity tools, such as spreadsheets, and personal databases such as Microsoft Access. To generate data, you need to analyze information from such sources. You can then simplify data management by structuring this information into a database management system (DBMS). However, this process of moving data from multiple sources to a single DBMS is quite expensive. This has led to the development of Microsoft’s Universal Data Access (UDA) strategy, which is based on COM. This strategy aims at providing access to a variety of data sources. Figure 13-1 displays Microsoft’s UDA architecture.
It is evident from the following figure that applications requiring data, such as VB applications, and ASP pages, are able to access data from varied data providers by using various data access techniques, such as ODBC.
It has been mentioned earlier that the data access technique to be used for an application is decided keeping in mind the data access requirements of the
INTRODUCTION TO ADO.NET |
Chapter 13 |
447 |
|
|
|
|
|
Data consumers |
|
Visual Basic application |
Visual C++ application |
ASP page |
Other applications |
|
ADO |
Service components
Query processor |
Query processor |
Data Providers
ODBC provider |
ODBC provider |
ODBC provider |
ODBC
Mainframe
Non-
data
Relational
data Database
Database
FIGURE 13-1 Microsoft’s UDA architecture
application. There are various data access techniques that are available that you can choose from. These techniques are listed as follows:
Data Access Object (DAO)
Open Database Connectivity (ODBC)
Remote Data Object (RDO)
448Project 3 ADO.NET IN MANAGED C++
OLE DB
ActiveX Data Object (ADO)
This section explains the evolution of each of these data access techniques in detail.
In recent times, there has been a rapid development of various new application programming interfaces (APIs) that enable you to easily access data from databases. You might already know that an API refers to a set of routines exposed by an operating system and used for making requests to the operating system or other programs, such as a DBMS.
Initially, DB-Libraries were used to access data in a database. However, DBLibraries made the client application dependent on the database server because DB-Libraries were optimized for accessing data in a specific relational database management system (RDBMS). These problems led to the development of ODBC. ODBC is an API that provides access to a variety of relational data sources. ODBC is used for connecting and sending SQL statements to the data source and retrieves results from the data source.
Another API, called Data Access Object (DAO), was designed by Microsoft as a data access model for Microsoft Jet databases, which are in the form of .mdb files. Just like ODBC, DAO also enables you to access data from varied data sources. DAO also provides support for ISAM data sources, such as FoxPro, dBase, and Paradox, and data sources based on ODBC.
However, there are some disadvantages of using DAO. The performance of DAO is optimized primarily for Microsoft Access and not for ODBC. This means that DAO is more suited for local databases on the client machine itself than the databases on the server. Moreover, DAO cannot be used in scenarios where the connection with the database is not established. In addition, since DAO is slow and uses a lot of resources, DAO is not appropriate in cases where you need to access data from remote data sources.
To overcome these problems, Microsoft developed an enhancement over DAO called Remote Data Objects (RDO), designed primarily to enable access to remote ODBC relational data sources. As compared to DAO, RDO is a smaller, quicker, and more sophisticated data access model. It provides high performance when accessing remote ODBC data sources. It also provides support for complex cursors and manages them programmatically. In addition, RDO can execute queries against stored procedures. Unlike DAO, RDO has an important feature in that the execution of a single query or stored procedure can return multiple result sets. However,
INTRODUCTION TO ADO.NET |
Chapter 13 |
449 |
|
|
|
|
|
just like DAO, RDO could not be used efficiently for disconnected architectures.
Both DAO and RDO catered to relational databases. Thus, there was a requirement for a data access model that could also support non-relational databases. This led to the development of OLE DB and ActiveX Data Objects (ADO). Microsoft based this model entirely on Component Object Model (COM) and ensured that it could work with structured data sources.
OLE DB is basically designed to enable you to access data from not only databases but also other varied sources, such as spreadsheets, e-mail, or the Web. OLE DB consists of a set of interfaces that represent data from various relational or non-relational data sources and enable applications to uniformly access data from varied sources. To display data from such sources, OLE DB makes use of COM. Due to the complexity of the interfaces, OLE DB is not primarily designed for direct access from Visual Basic. Therefore, ADO is used to encapsulate and depict the functionality of OLE DB.
ADO presents an application-level, easy-to-use interface for OLE DB. This interface provides high-performance access to various types of data sources, such as databases, e-mail, file systems, text, graphics, customized business objects, and ODBC data sources that already exist. Moreover ADO is language-independent, uses minimum network traffic, and the layers separating the client application and the data source are very few. These features of ADO ensure high speed and performance along with consistency in data access. ADO also enables you to create front-end clients for a database or middle-tier components as business objects that an application, a language, a tool, or a Web browser can use. In addition, though ADO offers lesser objects as compared to DAO and RDO, ADO objects contain more properties, models, and events than those contained by DAO and RDO objects. Also, unlike DAO and RDO, ADO provides support for disconnected data access. It can work in both connected and disconnected architectures, but is more suitable for connected architectures. You can also use ADO with Remote Data Services (RDS) to work with distributed applications on the Web. RDS enables ADO to manage advanced recordset cache and helps in easy exchange of data between the client and the server by caching data for the client.
NOTE
RDS is a mechanism introduced by Microsoft and is used to access remote data, which can be across the Internet or intranet.
