ado| Data | database | String in the process of network programming, ADO (Activex Data Object) programming is often indispensable work, especially the development of e-commerce sites. Now that you're talking about ADO data objects, you can simply introduce ADO data objects and their functions. There are seven separate objects for ADO data objects, namely, connection objects (Connection), Recordset objects (recordsets), Domain objects (field), Command objects (commands), Parameter objects (Parameter), Attribute objects (property) and Error objects (errors). features see Appendix 1.
ADO Data objects are used to connect to a database in two ways, ODBC and OLE DB, respectively, and the following are examples of connecting to a database in both ways.
The first type: 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
The second type: OLE DB Data Provider connections
OLE DB Provider for Active Directory Service
OLE DB Provider for DB2
Old DB Provider for 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'll start with ODBC DSN to access the database, to complete this work, you must first through the Control Panel-Administrative Tools-ODBC data source to establish a data source name, for example, called Testdata_resoure.
1 connection through System data source (systems DSN)
<%
Dim Oconn,strconn
Set oconn=server.createobject ("ADODB. Connection ")
Strconn= "Dsn=testdata_resoure" & _
"Uid=adminaccount;" & _
"Pwd=password;
oConn.Open strconn
%>
2 connection via file data source (Files DSN)
<%
Dim Oconn,strconn
Set oconn=server.createobject ("ADODB. Connection ")
Strconn= "Filedsn=c:\somepath\mydb.dsn" & _
"Uid=adminaccount;" & _
"Pwd=password;"
oConn.Open strconn
%>
3 Connection through Connection pool (dsn-less) (ODBC Driver for as/400)
<%
Dim Oconn,strconn
Set oconn=server.createobject ("ADODB. Connection ")
strconn= "Driver={client Access ODBC Driver (32-bit)};" & _
"SYSTEM=MYAS400;" & _
"Uid=myusername;" & _
"Pwd=mypassword;"
oConn.Open strconn
%>
Second, using the database driver directly access the database connection string.
1) ODBC Driver for Access
The standard is also the more common connection method
<%
Dim Oconn,strconn
Set oconn=server.createobject ("ADODB. Connection ")
strconn= "Driver={microsoft Access Driver (*.mdb)};" & _
"Dbq=" &server.mappath ("Testdb.mdb"); & _
"Uid=adminaccount;" & _
"Pwd=password;"
oConn.Open strconn
%>
If it is a workgroup system database, then the connection string is as follows
<%
Dim Oconn,strconn
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 strconn
%>
If the database (MDB) is shared on the network, the connection string is as follows
<%
Dim Oconn,strconn
Set oconn=server.createobject ("ADODB. Connection ")
strconn= "Driver={microsoft Access Driver (*.mdb)};" & _
"Dbq=\\myserver\myshare\mypath\testdb.mdb;"
oConn.Open strconn
%>
2) ODBC Driver for DBASE
<%
Dim Oconn,strconn
Set oconn=server.createobject ("ADODB. Connection ")
strconn= "Driver={microsoft DBASE Driver (*.dbf)};" & _
"DRIVERID=277;" & _
"Dbq=c:\filepath;"
oConn.Open strconn
%>
Note: The point to be noted here is to specifically specify the database file name in the SQL query statement, for example:
oRS.Open "SELECT * from testdb.dbf", oconn,,, adCmdText
3 ODBC Driver for Excel
<%
Dim Oconn,strconn
Set oconn=server.createobject ("ADODB. Connection ")