Introduction to the data access module of Microsoft enterprise database 4.1 Study Notes ()

Source: Internet
Author: User

The Unity module is still difficult for me to learn. Many things are the first time I learned, and some things are not easy to understand. So the content behind the Unity module should be understood by myself, let's add them later. Let's start with the subsequent chapters. After reading about the content behind Unity, we plan to leave four blogs for it. Therefore, the data access module starts from and thanks for your support.

Next let's go back to the question.

Introduction to Data Access Appliction Block

The data access module of the enterprise database provides common data access functions, which simplifies the development work. Applications can use this module in various situations, such as reading data from a database for display, passing data through the application layer, and submitting data to the database system. The module supports stored procedures and SQL statements. Common housekeeping functions, such as connection management, creation, and cache parameters, are encapsulated in the module. In other words, the data access module provides common functions in ADO. NET in a simple way, improving the development productivity.

ADO. NET provides classes such as DbCommand and DbConnection, which help developers abstract data providers from special database implementations. The module uses these classes to provide a model that supports specific functions of data types, such as parameter discovery and type conversion. Because of this, the application can switch from one database to another without modifying the client code. The module contains an abstract class that contains common interfaces and provides most of the data access methods.

The module also provides operation classes for specified databases, such as SQL Server, Server CE, and Oracle. These classes contain operation methods for the specified database. Code written for a database, such as SQL Server, looks similar to the code written for other databases, such as Oracle.

Another function of the module is to connect to a specified database by using the name of the database string. You can also pass the specified name as a parameter to the DatabaseFactory. CreateDatabase method. Each database with the specified name stores connection information in the configuration file. By modifying the configuration information, developers can run applications on different databases without compiling code.

The data access module provides the following benefits:

  • To use the functions of ADO. NET2.0, ADO. NET2.0 can be used together with the module's data access function.
  • Reduces the Code required to implement standard functions.
  • It helps maintain consistent data access experience between applications and various enterprise applications.
  • This reduces the difficulties caused by database changes.
  • Reduces the learning curve of different models in different databases during development.
  • This reduces the amount of code that developers need to write for different databases.

Common solutions

Developers often write some database access code. Because it is too common, developers will find that they are writing repeated code when developing each application. In addition, these applications may need to work on different database systems. Although these functions are similar, the Code must adapt to the programming models of different databases. The data access module provides a general method to solve these problems. Developers only need to do the following:

  • Create a database object
  • Provide parameters for command if needed
  • Call appropriate methods, which are optimized and lightweight.

The database access module can operate SQL Server, SQL Server CE, and Oracle databases. The purpose of the design is to solve common tasks for developers in the face of database operations. Common Data Access scenarios are listed below:

  • Use DataReader to obtain multi-row data
  • Use DataSet to obtain multi-row data
  • Run a command to obtain the output parameter value.
  • Run a command to obtain the value of a single project.
  • Use transactions to complete multiple operations
  • Obtain XML data from SQL Server
  • Use the value in DataSet to update the database

Sample Code

The following code uses a stored procedure and returns the DataSet

  

 

Database db = DatabaseFactory. createDatabase (); DbCommand dbCommand = db. getStoredProcCommand ("GetProductsByCategory"); // Retrieve products from category 7. db. addInParameter (dbCommand, "CategoryID", DbType. int32, 7); DataSet productDataSet = db. executeDataSet (dbCommand );

 

  

When to use the data access module

The module contains a large number of methods to simplify common database access tasks. Each method encapsulates the logic and database connection management required to access data. If your application uses a standard data access method, you can consider using the data access module.

The module supports using the same code in different databases. These classes support SQL Server and Oracle. These codes also include special implementations for databases, including parameter processing and cursor processing. In addition, the GenericDatabase class allows the application to use any configured ADO. NET DbProviderFactory object. You can add a new database type to expand the module, which contains the special functions of the database, or provide a custom implementation for the existing data. The only condition is that an ADO. NET DbProviderFactory class exists in the target database.

When to access the database directly using ADO. NET

The data access module supplements ADO. NET, instead of replacing ADO. NET. The module provides developers with a best practice when using ADO. NET. If your application needs to obtain data in a special way, if your code needs custom operations for a special database, it may be better for you to directly use ADO. NET.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.