Connect the characters of various databases through the ADO (2) (End)

zhaozj2021-02-16  50

Connect the character servings of various databases via ADO

Hainan Provincial Information Service Center Wen Wen

((Connected)

Second, the next example uses OLE DB to connect to the database.

1) OLE DB Provider for Active Directory Service

<%

DIM OCONN, STRCONNNN

Set Oconn = Server.createObject ("AdoDb.Connection")

StrConn = "provider = adsdsoObject;" & _

"User ID = myusername;" & _

"Password = mypassword;"

Oconn.open straconn

%>

2) OLE DB Provider for DB2

<%

DIM OCONN, STRCONNNN

Set Oconn = Server.createObject ("AdoDb.Connection")

Strconn = "provider = db2oledb;" &

"NetWork Transport Library = TCPIP;" &

"NetWork address = myserver;" & _

Package Collection = Mypackage; &

Host CCSID = 1142

Initial Catalog = MyDB; &

"User ID = myusername;" & _

"Password = mypassword;"

Oconn.open straconn

%>

3) OLE DB Provider for INDEX Server

<%

DIM OCONN, STRCONNNN

Set Oconn = Server.createObject ("AdoDb.Connection")

StrConn = "provider = msidxs;" & _

Data Source = MyCatalog; "

Oconn.open straconn

%>

4) OLE DB Provider for Internet Publishing

<%

DIM OCONN, STRCONNNN

Set Oconn = Server.createObject ("AdoDb.Connection")

StrConn = "provider = msdaipp.dso;" & _

"Data Source = http: // mywebsite / mydir;" & _

"User ID = myusername;" & _

"Password = mypassword;"

Oconn.open straconn

%>

5) OLE DB Provider for Microsoft Jet

● The standard is also a commonly used access method.

<%

DIM OCONN, STRCONNNN

Set Oconn = Server.createObject ("AdoDb.Connection")

StrConn = "provider = microsoft.jet.Oledb.4.0;" & _

"Data Source = C: /SOMEPATH/Mydb.mdb;" & _ "User ID = admin;" & _

"Password =;"

Oconn.open straconn

%>

● If it is a system database of a workgroup, then the connection string is as follows.

<%

DIM OCONN, STRCONNNN

Set Oconn = Server.createObject ("AdoDb.Connection")

StrConn = "provider = microsoft.jet.Oledb.4.0;" & _

"Data Source = C: /SOMEPATH/Mydb.mdb;" & _

"Jet OLEDB: System Database = mysystem.mdw;", _

"admin", ""

Oconn.open straconn

%>

Note: When using the 4.0 OLE DB Provider provider's driver, remember to convert MDB and MDW to the 4.0 database format.

● If the MDB is set a password, then connect the string as follows.

Oconn.open "provider = microsoft.jet.Oledb.4.0;" & _

"Data Source = C: /SOMEPATH/Mydb.mdb;" & _

"Jet OLEDB: Database Password = mydbpassword;", _

"admin", ""

● If the MDB is in the network and is shared, then the following connection string is used.

Oconn.open "provider = microsoft.jet.Oledb.4.0;" & _

"Data Source = // myserver / myshare / mypath / mydb.mdb;

● If you want to use a proprietary way to access the database, use the following connection string.

Oconn.mode = admodeshareExClusive

Oconn.open "provider = microsoft.jet.Oledb.4.0;" & _

"Data Source = C: /SOMEPATH/Mydb.mdb;" & _

"User ID = admin; password =;"

6) Use the OLE DB Provider for Microsoft Jet to access the Excel electronic data table.

<%

DIM OCONN, STRCONNNN

Set Oconn = Server.createObject ("AdoDb.Connection")

StrConn = "provider = microsoft.jet.Oledb.4.0;" & _

"Data Source = c: /somepath/myexcelspreadsheet.xls;" & _

"Extended Properties =" "Excel 8.0; HDR = YES;" ";"

Oconn.open straconn

%>

Description: The HDR = YES here is that the provider does not add the first row of data to the data set when the provider accesses the Excel electronic data; and when HDR = No means that the provider is just right when the provider accesses the Excel electronic data table. Contrary to the above. 7) OLE DB Provider for ODBC Databases

● Access MS Access Database

<%

DIM OCONN, STRCONNNN

Set Oconn = Server.createObject ("AdoDb.Connection")

StrConn = "provider = msdasql;" & _

"Driver = {Microsoft Access Driver (* .mdb)};" & _

"DBQ = C: /SOMEPath/mydb.mdb;" & _

"UID = myusername;" & _

"Pwd = mypassword;"

Oconn.open straconn

%>

● Access MS SQL Server Database

<%

DIM OCONN, STRCONNNN

Set Oconn = Server.createObject ("AdoDb.Connection")

StrConn = "provider = msdasql;" & _

Driver = {SQL Server}; "& _

"Server = myservername;" & _

"Database = MyDatabaseName;" & _

"UID = myusername;" & _

"Pwd = mypassword;"

Oconn.open straconn

%>

8) OLE DB Provider for Oracle (from Microsoft)

<%

DIM OCONN, STRCONNNN

Set Oconn = Server.createObject ("AdoDb.Connection")

StrConn = "provider = msdara;" & _

"Data Source = Myoracledb;" & _

"User ID = myusername;" & _

"Password = mypassword;"

Oconn.open straconn

%>

9) OLE DB Provider for Oracle (from oracle)

<%

DIM OCONN, STRCONNNN

Set Oconn = Server.createObject ("AdoDb.Connection")

StrConn = "provider = oraoledb.oracle;" & _

"Data Source = Myoracledb;" & _

"User ID = myusername;" & _

"Password = mypassword;"

Oconn.open straconn

%>

10) OLE DB Provider for SQL Server

● Standard connection method

<%

DIM OCONN, STRCONNNN

SET OCONN = Server.createObject ("AdoDb.Connection" StrConn = "provider = SQLOLEDB;" & _

"Data Source = MyServerName;" & _

"Initial Catalog = MyDatabaseName;" & _

"User ID = myusername;" & _

"Password = mypassword;"

Oconn.open straconn

%>

● Access to the IP address of the machine

<%

DIM OCONN, STRCONNNN

Set Oconn = Server.createObject ("AdoDb.Connection")

StrConn = "provider = SQLOLEDB;" & _

"Data Source = xxx.xxx.xxx.xxx, 1433;" & _

"NetWork Library = DBMSSOCN;" & _

"Initial Catalog = MyDatabaseName;" & _

"User ID = myusername;" & _

"Password = mypassword;"

Oconn.open straconn

%>

Description: IP: xxx.xxx.xxx.xxx

SQLServer default port: 1433

Appendix 1:

Introduction to ADO Data Object and Its Function

ADO data object

Features

.Connection

Represents a unique conversation with a data source

.Command

With Command objects, you can perform stored procedures, SQL queries, and SQL statements with parameters. You can receive the Recordset object using the Command object.

.Recordset

Used to represent a database table.

.Error

This object contains all errors and warning messages. This object only has attribute values.

.Field

The Field object represents a column in the data set.

.Parameter

Parameter objects are used to provide the parameters required for the SQL query or stored procedure to be parameters, or return values ​​from the stored procedure.

.Property

Represents the specific properties of the data provider.

(Full text)

转载请注明原文地址:https://www.9cbs.com/read-23247.html

New Post(0)