Database access interface (ODBC, OLEDB, ADO)

Database access interface development history

ODBC

ODBC (Open Database Connectivity, Open Database Connectivity). To understand what ODBC is to first look at the knowledge database connection. In the beginning when connecting to the database, because the database a wide range of variety of database connections have different needs, this time, the database connection rely mainly on a variety of API functions to connect. In this context, Microsoft ODBC published in 1992, these ODBC API functions is to form a unified interface to package together. When entering the interface to the SQL statement, the drive management program them into corresponding drive (Driver), SQL statements by the driver into a variety of different databases.

OLE DB

OLE DB (Object Linking and Embedding, Database, Object Linking embedded database) is a Microsoft Access to store different types of data in a uniform manner designed an application program interface. OLE DB ODBC functionality is built on top of an open specification. ODBC was created to access relational database specifically developed, OLE DB is used to access relational and non-relational sources. OLE DB can connect to the database through ODBC, you can also connect directly to the database, and access speed direct connections faster. You may know, as long as the support for ODBC data sources is certainly able to support OLEDB, but the reverse is not necessarily.

ADO

ADO (ActiveX Data Objects, ActiveX Data Objects) was released in August 1996 together with the OLE DB, is a new high-level object model of unified data access in the OLE DB created above. After the successful launch ADO substituted Microsoft early data access object layer (including RDO (Remote Data Objects) and DAO (Data Access Objects)). ADO object model OLE DB is further simplified by database vendors developed to meet data provided by OLE DB interface (data provider), and ADO itself is the data source independent (data source independent) object structure, which makes the versatile ADO excellent.

The relationship between ODBC, OLEDB and ADO

Database interface code sample under VB Script

OLEDB connection

Standard security mode (Standard Security)

dim conn, sCon
set conn=server.CreateObject("ADODB.Connection")
sCon="Provider=SQLOLEDB;Data Source=(local); Initial Catalog =dbname;User ID=sa;Password=123"
conn.open(sCon)

Trust connection (Trusted connection)

dim conn, sCon
set conn=server.CreateObject("ADODB.Connection")
sCon="Provider=SQLOLEDB; Integrated Security=SSPI; Persist Security Info=False;Data Source=(local); Initial Catalog =dbname"
conn.open(sCon)

ODBC connection

Via system data source (System DSN)

To register the data source: DSN. Open Administrative Tools -> Data Sources (ODBC) -> Open the System DSN tab -> click the Add button -> select SQL Server from the list and click Finish -> Enter the database name in a name, you want to connect to SQL server server, enter (local) -> Follow the wizard prompts to complete.

dim conn, sCon
set conn=server.CreateObject("ADODB.Connection")
sCon="DSN=注册名;Uid=sa;Pwd=123"
conn.open(sCon)

Connects through the ODBC driver

dim conn, sCon
set conn=server.CreateObject("ADODB.Connection")
sCon="Driver={SQL Server};Server=(local); Uid=sa;Pwd=123;Database=dbname"
conn.open(sCon)

How to query OLE DB data sources in SQL Server

Create a linked server

Configuring the linked server to access SQL Server Database Engine OLE DB data source other than SQL Server instance.

In SQL Server Management Studio, open Object Explorer, expand the "server object" right-click "for linked server" and click "New Linked Server."

In the "General" page, "linked server" column for the linked server name, and fill in other information. 

Links database query

Perform pass-through query on the specified linked server. The syntax is as follows:

OPENQUERY ( linked_server ,'query' )  

parameter:

  • linked_server: an identifier representing a linked server name.
  • 'Query': the query string executed in the linked server. The maximum length of the string is 8 KB.

FROM OPENQUERY can be referenced in clause of a query as if it is a table name

SELECT * FROM OPENQUERY (OracleSvr, 'SELECT name FROM joe.titles WHERE name = ''NewTitle'''); 

 

Guess you like

Origin www.cnblogs.com/yada/p/11726075.html