Connect the character servings of various databases via ADO
Hainan Provincial Information Service Center Wen Wen
During the network programming, Ado (ActiveX Data Object) programming is often indispensable, especially developing an e-commerce website. Since the ADO data object is told, then the ADO data object and its functions are briefly introduced. ADO data objects have seven independent objects, which are connected, recorded, recorded, command objects, parameter objects, properties, and Property, and Error Object (Error). See Appendix 1 for the function.
There are two ways to connect the database to connect to the database, which are ODBC and OLE DB mode, and the following describes an example of connecting to the database in both ways.
First: ODBC DSN-Less Connections
ODBC DRIVER FOR Access
ODBC Driver for DBASE
ODBC Driver for Excel
ODBC DRIVER for Mysql
ODBC Driver for Oracle
ODBC DRIVER for PARADOX
ODBC DRIVER for SQL Server
ODBC DRIVER for Sybase
ODBC Driver for Sybase SQL Anywhere
ODBC Driver for Text
ODBC Driver for Teradata
ODBC Driver for Visual FoxPro
Second: OLE DB DATA Provider Connections
OLE DB Provider for Active Directory Service
OLE DB Provider for DB2
Old DB Provider for Internet Publishing, INTERNET PUBLISHING
OLE DB Provider for Index Server
OLE DB Provider for Microsoft Jet
OLE DB Provider for ODBC Databases
OLE DB Provider for Oracle (from Microsoft)
OLE DB Provider for Oracle (from oracle)
OLE DB Provider for Simple Provider
OLE DB Provider for SQL Server
First, I will first use the ODBC DSN to access the database. To complete this work, you must first create a data source in the "Control Panel" - "ODBC Data Source", such as TestData_Resoure.
1) Connection through the System Data Source (System DSN)
<%
DIM OCONN, STRCONNNN
Set Oconn = Server.createObject ("AdoDb.Connection")
StrConn = "DSN = TestData_Resoure;" & _
"UID = admincount;" & _
PWD = Password;
Oconn.open straconn
%>
2) Connection to File DSN
<%
DIM OCONN, STRCONNNN
Set Oconn = Server.createObject ("AdoDb.Connection")
StrConn = "fileDSN = c: /somepath/mydb.dsn;" & _ "uid = admincount;" & _
"Pwd = password;"
Oconn.open straconn
%>
3) Connection to DSN-Less (ODBC Driver for AS / 400)
<%
DIM OCONN, STRCONNNN
Set Oconn = Server.createObject ("AdoDb.Connection")
StrConn = "driver = {Client Access ODBC Driver (32-bit)};" & _
"System = myas400;" & _
"UID = myusername;" & _
"Pwd = mypassword;"
Oconn.open straconn
%>
Second, using the database driver directly accesses the connection string of the database.
1) ODBC DRIVER FOR Access
● The standard is also a relatively common connection method
<%
DIM OCONN, STRCONNNN
Set Oconn = Server.createObject ("AdoDb.Connection")
StrConn = "driver = {Microsoft Access Driver (* .mdb)};" & _
"DBQ =" & Server.mappath ("Testdb.mdb"); & _
"UID = admincount;" & _
"Pwd = password;"
Oconn.open straconn
%>
● If it is a system database of a working group, then the connection string is as follows.
<%
DIM OCONN, STRCONNNN
Set Oconn = Server.createObject ("AdoDb.Connection")
StrConn = "driver = {Microsoft Access Driver (* .mdb)};" & _
"DBQ = C: /DataPath/testdb.mdb;" & _
"Systemdb = c: /dataPath/testdb.mdw;", _
"admin", ""
Oconn.open straconn
%>
● If the database (MDB) is shared on the network, then the connection string is as follows.
<%
DIM OCONN, STRCONNNN
Set Oconn = Server.createObject ("AdoDb.Connection")
StrConn = "driver = {Microsoft Access Driver (* .mdb)};" & _
"DBQ = // myserver / myshare / mypath / testdb.mdb;"
Oconn.open straconn
%>
2) ODBC Driver for DBASE
<%
DIM OCONN, STRCONNNN
Set Oconn = Server.createObject ("AdoDb.Connection")
StrConn = "driver = {Microsoft DBase Driver (* .dbf)};" & _
Driverid = 277; "& _
"DBQ = C: / filepath;"
Oconn.open straconn
%>
Note: One thing to note here is that in the SQL query statement, specify specified database file names, for example:
Ors.open "Select * from testdb.dbf", Oconn,, AdcmdText
3) ODBC Driver for Excel
<%
DIM OCONN, STRCONNNN
Set Oconn = Server.createObject ("AdoDb.Connection")
StrConn = "driver = {Microsoft Excel Driver (* .xls)};" & _
Driverid = 790; "& _
"Dbq = c: /filepath/myexecl.xls;"
Oconn.open straconn
%>
4) ODBC Driver for MySQL (via myodbc driver)
● Connect to the local database (LOCAL DATABASE)
<%
DIM OCONN, STRCONNNN
Set Oconn = Server.createObject ("AdoDb.Connection")
StrConn = "driver = {mysql};" & _
"Server = Servername;" & _
Option = 16834; "& _
"Database = mydb;"
Oconn.open straconn
%>
● Connect the remote database (Remote Database)
<%
DIM OCONN, STRCONNNN
Set Oconn = Server.createObject ("AdoDb.Connection")
StrConn = "driver = {mysql}; server = db1.database.com; port = 3306;" & _
"Option = 131072; stmt =; dataBase = mydb; uid = myusername; pwd = mypassword;"
Oconn.open straconn
%>
5) ODBC Driver for Oracle
<%
DIM OCONN, STRCONNNN
Set Oconn = Server.createObject ("AdoDb.Connection")
StrConn = "driver = {microsoft odbc for oracle};" & _
"Server = oracleserver.world;" & _
"UID = myusername;" & _
"Pwd = mypassword;"
Oconn.open straconn
%>
6) ODBC Driver for Paradox
<%
DIM OCONN, STRCONNNN
Set Oconn = Server.createObject ("AdoDb.Connection")
StrConn = "driver = {Microsoft Paradox Driver (* .db)};" & _
"Driverid = 538;" & _ "fil = paradox 5.x;" & _
"Defaultdir = c: / dbpath /;" & _
"DBQ = C: / dbpath /;" & _
"Collatingsequence = ascii;"
Oconn.open straconn
%>
7) ODBC Driver for SQL Server
<%
DIM OCONN, STRCONNNN
Set Oconn = Server.createObject ("AdoDb.Connection")
StrConn = "driver = {SQL Server};" & _
"Server = myservername;" & _
"Database = MyDatabaseName;" & _
"UID = myusername;" & _
"Pwd = mypassword;"
Oconn.open straconn
%>
8) ODBC Driver for Sybase (via Sybase System 11 ODBC Driver Driver)
<%
DIM OCONN, STRCONNNN
Set Oconn = Server.createObject ("AdoDb.Connection")
StrConn = "driver = {Sybase System 11};" & _
"SRVR = MyServerName;" & _
"UID = myusername;" & _
"Pwd = mypassword;"
Oconn.open straconn
%>
9) ODBC Driver for Sybase SQL Anywhere
<%
DIM OCONN, STRCONNNN
Set Oconn = Server.createObject ("AdoDb.Connection")
StrConn = "ODBC; driver = Sybase SQL Anywhere 5.0;" & _
"Defaultdir = c: / dbpath /;" & _
"Dbf = c: /sqlany50/mydb.db;" & _
"UID = myusername;" & _
"Pwd = mypassword;"
"DSN =" "" ";"
Oconn.open straconn
%>
10) ODBC Driver for Teradata
<%
DIM OCONN, STRCONNNN
Set Oconn = Server.createObject ("AdoDb.Connection")
StrConn = "provider = teradata;" & _
"Dbcname = mydbcname;" & _
"Database = MyDatabaseName;" & _
"UID = myusername;" & _
"Pwd = mypassword;"
Oconn.open straconn
%>
11) ODBC Driver for Text
<%
DIM OCONN, STRCONNSET OCONN = Server.createObject ("AdoDb.Connection")
StrConn = "driver = {Microsoft Text driver (* .txt; * .csv)};" & _
"DBQ = C: / SomePath /;" & _
"Extensions = ASC, CSV, Tab, TXT;" & _
"Persist security info = false"
Oconn.open straconn
%>
12) ODBC Driver for Visual FoxPro
● Use the database container connection method
<%
DIM OCONN, STRCONNNN
Set Oconn = Server.createObject ("AdoDb.Connection")
StrConn = "driver = {Microsoft Visual FoxPro Driver};" & _
"SourceType = DBC;" & _
"SOURCEDB = C: /SOMEPATH/Mysourcecedb.dbc;" & _
"EXclusive = NO;"
Oconn.open straconn
%>
● Do not use the database container connection mode (ie Free Table Directory mode)
<%
<%
DIM OCONN, STRCONNNN
Set Oconn = Server.createObject ("AdoDb.Connection")
StrConn = "driver = {Microsoft Visual FoxPro Driver};" & _
SourceType = DBF; "& _
"SOURCEDB = C: / somepath / mysourcedbfolder;" & _
"EXclusive = NO;"
Oconn.open straconn
%>
(Endlessly)
KDSFJK