. NET Connection Database mode

Source: Internet
Author: User
Tags dbase driver manager ole oracleconnection

. NET Connection Database mode

1. Connect Oracle

A oracleclient approach that Microsoft has developed specifically for Oracle databases (typically used)
Reference Class Library: System.Data.OracleClient.dll
Namespaces: System.Data.OracleClient
Common classes: OracleConnection, OracleCommand, OracleDataAdapter, oracletransaction, OracleDataReader, etc.
Connection string: "Data source=**" Network Configuration service Name "user id=**;p assword=**" Table "" (Note: Provider driver can not be specified)

     Reference class Library: System.Data.dll
namespace: System.Data.OleDb
Common classes: OleDbConnection, OleDbCommand, OleDbDataAdapter, OleDbTransaction, OleDbDataReader and so on.
connection string: To add a provider, "provider=msdaora.1;" compared to OracleClient mode.
     Short board: Handling Complex SQL, BLOB fields

three  oracle provides Oracle Data Provider for. NET (odp.net )
    reference class Library: Oracle.DataAccesss.dll "Install Oracle for. NET installation package Oracle Data Provider for. Net "
    Namespaces: Oracle.DataAccess.Client and Oracle.DataAccess.Types " Oracle.DataAccess.Client is used to set the connection of the database, and so on common functions, Oracle.DataAccess.Types for setting

2. Connect to SQL Server

Ado,ado.net,oledb,odbc one. ADO

ADO (ActiveX Data Objects) is a COM group that is used to access data sources. It provides a middle layer of the OLE DB in the form of a programming language and a single-digit interview. Allow developers to write access codes without having to worry about how the repository is actually being used, and only connect to the repository with a heart. When visiting the repository, the knowledge about SQL is not necessary, but the SQL commands supported by the specific repository can still be executed through the command in ADO.

Frame structure

ADO is designed to continue to be a very early Access to the image layer, including RDO (Remote data Objects), and DAO (data Objects). ADO was invented in the winter of 1996.

ADO contains some of the top images:

    • Connect (Connection), representing the connection to the repository
    • Record set (Recordset), representing a collection of repository records
    • command, which represents an SQL command
    • Record, which represents a collection of numbers
    • Stream, which represents the sequential set of numbers
    • Error, which represents an accident in the information library
    • Linked fields bit (Field), which represents a repository linked fields bit
    • Parameters (Parameter), which represents a SQL parameters
    • property, storing information about the image

The use of ADO components requires the use of high-level languages that support COM, such as VBScript in ASP or Visual Basic.

Basic functions

Some basic steps for accessing the information using ADO:

    1. Create a link to connect the database (create a Connection object to connect to the.)
    2. Generate a Recordset object to get the information (create a Recordset object in order to receive data in.)
    3. Opening a link (Open the connection)
    4. Complete the description of SQL language in the recordset (Populate the recordset by opening it and passing the desired table name or SQL statement as a parame ter to open function.)
    5. The desired searching/processing on the fetched data.
    6. Make sure to change the information (Commit the changes you made to the data (if any) by using Update or UpdateBatch methods.)
    7. Closed Recordset (Close the Recordset)
    8. Closed connection (Close the connection)

ExampleCode Private Functionexist (ptileAs String)As BooleanDimstrSQLAs StringstrSQL= "Select 1 from g_srp_info where tile= '" &Ptile& "‘"DimIntrsopentypeAs IntegerIfMadocnIs Nothing ThenExit FunctionEnd IfDimAdorsAsADODB. RecordsetSetAdors= NewADODB. Recordset Intrsopentype=adOpenStatic adors.cursorlocation=adUseClient Adors.open strSQL, MADOCN, Intrsopentype, adLockOptimisticIf Cstr(Adors (0))= 1 " then          exist = true     else         exist =< Span style= "color: #000000;" > false     end if end Function

Two. ADO

Ado. NET is a kind of repository that is used in the. NET Framework to take responsibility for information access, which is made possible by using the OLE DB technology that was laid out in COM and the. NET Framework's library and programming language. NET has the ability to connect and access relational repositories and non-repository sources (such as xml,excel or text files), or a category of objects that stand out as application programs, which in the. NET Framework have a very heavy weight, and that is the most important thing. Many people will be the next version of ADO, but in fact it is a new structure, product and concept.

Frame structure

Ado. The net-image model has five major pairs of connection, command-like, Dataadpter-like, The dataset pair as well as the DataReader. These are responsible for establishing the connection and the operation of the part we call ' the operation of the image ' (Managed Provider), divided by the connection, the command-like, Dataadpter and DataReader to the elephant. The operation of the digital operations is primarily a bridge between the dataset and the source, which is responsible for taking the numbers from the source and storing them in the dataset to manage the image, as well as the work of storing the numbers back into the source.

    1. Connection: You can open the connection between the program and the source. There is no use of the connection to open the source of the sources, and it is impossible to obtain the numbers from the source.
    2. Command image: Use to produce instructions for the source, such as the source to inquire, add, modify, delete the numbers and other instructions.
    3. Dataadpter: It is mainly the work of running the material between the source and the dataset, which can be managed by placing the obtained information into a dataset after command commands.
    4. DataSet to Image: As a cache, you can reserve the information from the source and even display the entire source of the information as it is used to do so. "--" It can not only save multiple tables, but also through the dataadpter to obtain some of the key, such as the table structure, and can record the relationship between the table.
    5. DataReader: You can use DataReader if you only need to sequentially read the information in the source and no other operations are required. DataReader is a single stroke, reading the information from the source in a sequential way, and the DataReader to the image is read only and is not allowed to do anything else.

The relationships between the components are as follows:

Ado. NET and ADO differences

For the developers of ADO, the most obvious change in the past is that the recordset in ADO has disappeared, and it is clearly separated into a connected DataReader and a disconnected DataSet and DataTable, and has developed a browser tool that supports the source of the offline resources Datav Iew, this change, so that the use of ADO vb/asp developers will have a certain degree of not accustomed to, so that the learning of ADO is more complicated, so there are some new or VB 6.0/asp developers will learn the. NET framework or to make the. Use ADO to connect to sources in the. NET Framework when using vb.net to develop applications. However, in the. NET Framework application using ADO, the. NET Framework will cause a small amount of damage to the application's performance due to the conversion between a layer of COM and. NET material.

three. Old-db

Is Microsoft's strategic low-level application interface to different data sources. OLE DB includes not only the Structured Query Language (SQL) capability of the Microsoft-funded standard data Interface Open Database Connectivity (ODBC), but also access to other non-SQL data types.

As a design of Microsoft's Component Object Model (COM), OLE DB is a set of methods for reading and writing data (which in the past may be called a channel). The objects in the old DB mainly include the data source object, the stage object, the Command object, and the row group object. Applications that use OLE DB use the following request sequence: Initialize OLE to connect to the data source, issue commands, process results, release the data source object, and stop initializing OLE

Object Linking and embedding, objects connected with embedding, or OLE technology. OLE is not only a desktop application integration, but also defines and implements a mechanism that allows applications to "connect" to each other as software "objects" (data collections and operational data functions), which are called part object models.

OLE is an object-oriented technology that leverages this technology to develop reusable software components (COM). DB (full name data base, database) is organized according to a data model and holds data sets in Level two memory.
OLE DB divides a traditional database system into logical components that are relatively independent and communicate with one another. Each part of this component model is labeled with a different name:
    1. Data Provider: Software components that provide data storage, small to normal text files, complex databases large to the host, or e-mail storage, are examples of data providers. Some documents refer to developers of these software components as data providers.
    2. Data Service Provider (Provider): Functional components that are separated from the previous database management system and run independently, such as the query processor and cursor engine, on top of the data provider. These components enable data provider data to be represented in the form of tabular data (regardless of how the actual physical data is organized and stored), and to implement the query and modification functions of the data. The SQL Server 7.0 query handler is a typical example of this component.
    3. Business Component: A functional component that leverages a data service provider, specializes in a specific business process, and can be reused. The middle tier (Middle-tier) in a distributed database application system is a typical example of such a component.
    4. Data Consumer: Any system program or application that requires access to data, in addition to typical database applications, includes development tools or languages that require access to a variety of data sources.

OLE DB's relationship to ODBC

Since OLE DB and ODBC standards are all designed to provide a unified access data interface, it was once wondered if OLE DB was the new standard for ODBC. The answer is in the negative. In fact, the ODBC standard object is a SQL-based data source (sql-based), whereas OLE DB objects are any data store of a wider scope. In this sense, ODBC-compliant data sources are subsets of data stores that conform to OLE DB standards. ODBC-compliant data sources to conform to the OLE DB standard, you must also provide the appropriate OLE DB service program (service Provider), just as SQL Server must provide an ODBC driver for SQL Server to comply with ODBC standards. Now, Microsoft itself has provided a unified OLE DB service program for all ODBC data sources, called ODBC OLE DB Provider.

After the ODBC OLE DB Provider was released, it was also feared that the ODBC Provider was not a new layer (layer) above ODBC? If so, does using OLE DB access the ODBC data source affect performance? The answer, too, is negative. In fact, the role of ODBC Provider is to replace the ODBC Driver Manager as a bridge between the application and the ODBC driver, without theoretically adding any overhead.

Iv. ODBC

ODBC, open Database Connectivity, provides a standard API (application programming Interface) method to access the DBMS (Database Management System). These APIs use SQL to accomplish most of their tasks. ODBC itself also provides support for the SQL language, which allows users to send SQL statements directly to ODBC. ODBC designers strive to make it the most independent and open: independent of the specific programming language, independent of the specific database system, regardless of the specific operating system. Microsoft released the world's first ODBC product in 1993 as a DLL set, and is now an integral part of the Microsoft Open Service Architecture (Wosa,windows Open Services Architecture) database. Microsoft's ODBC product is actually an ODBC driver manager that provides an ODBC application to some kind of ODBC-driven interface. On UNIX systems, there are two open source ODBC driver managers, UNIXODBC and IODBC.

ODBC, open Database Connectivity, is an integral part of the database in the Microsoft Open Service Architecture (Wosa,windows Open Services Architecture), which establishes a set of specifications and provides a set of standard APIs (application programming interfaces) for database access. These APIs use SQL to accomplish most of their tasks. ODBC itself also provides support for the SQL language, which allows users to send SQL statements directly to ODBC.
An ODBC-based application operates on a database that does not rely on any DBMS, does not interact directly with the DBMS, and that all database operations are done by the corresponding DBMS's ODBC driver. That is, either FoxPro, Access, or an Oracle database can be accessed using the ODBC API. Thus, the greatest advantage of ODBC is the ability to handle all databases in a unified manner.
A complete ODBC consists of the following parts:

    • Application (application).
    • ODBC Administrator (Administrator): The program is located within the 32-bit ODBC of the Windows 95 Control Panel, and its primary task is to manage installed ODBC drivers and manage data sources.
    • Driver Manager (Driver Manager): The driver Manager is included in the ODBC32.DLL and is transparent to the user. Its task is to manage the ODBC driver, which is the most important part of ODBC.
    • ODBC API.
    • ODBC driver: is a number of DLLs that provide an interface between ODBC and the database.
    • Data source: A data source contains information such as database location and database type, and is actually an abstraction of a data connection.

To access a database, the application must first register a data source with the ODBC Administrator, which establishes the connection between ODBC and a specific database based on information such as the database location, database type, and ODBC driver provided by the data source. This allows the application to establish a connection to the corresponding database as long as the data source name is supplied to the ODBC,ODBC.
In ODBC, the ODBC API does not have direct access to the database and must exchange information with the database through the driver manager. The driver manager is responsible for passing the application's call to the ODBC API to the correct driver, and the driver returns the results to the application through the driver manager after performing the appropriate operation.
ODBC driver support is required when accessing an ODBC data source. With Visual C + + 5.0 Setup, you can install drivers such as SQL Server, Access, Paradox, DBase, FoxPro, Excel, Oracle, and Microsoft text. By default, VC5.0 only installs drivers for SQL Server, Access, FoxPro, and dBASE. If the user needs to install a different driver, you will need to rerun the Setup program for VC 5.0 and select the desired driver.

Five, the relationship between the components is shown:

  Microsoft offers the following four ways to connect to a database:

System.Data.OleDb.OleDbConnection

System.Data.SqlClient.SqlConnection

System.Data.Odbc.OdbcConnection

System.Data.OracleClient.OracleConnection

http://blog.csdn.net/stone0419/article/details/1783537

Http://www.cnblogs.com/upDOoGIS/archive/2009/09/12/1565438.html

Http://www.cnblogs.com/iswszheng/archive/2009/05/19/1460052.html

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.