ado| Data | database | string (next)
22. Next, let's talk about using OLE DB to connect to a database.
1 OLE DB Provider for Active Directory Service
<%
Dim Oconn,strconn
Set oconn=server.createobject ("ADODB. Connection ")
Strconn= "Provider=adsdsoobject" & _
"User id=myusername;" & _
"Password=mypassword;"
oConn.Open strconn
%>
2 OLE DB Provider for DB2
<%
Dim Oconn,strconn
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 strconn
%>
3 OLE DB Provider for Index Server
<%
Dim Oconn,strconn
Set oconn=server.createobject ("ADODB. Connection ")
Strconn= "Provider=msidxs" & _
"Data Source=mycatalog;"
oConn.Open strconn
%>
4 OLE DB Provider for Internet Publishing
<%
Dim Oconn,strconn
Set oconn=server.createobject ("ADODB. Connection ")
Strconn= "Provider=msdaipp. DSO; "& _
"Data Source=http://mywebsite/mydir;" & _
"User id=myusername;" & _
"Password=mypassword;"
oConn.Open strconn
%>
5 OLE DB Provider for Microsoft Jet
Standard is also the common way of access.
<%
Dim Oconn,strconn
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 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= "Provider=Microsoft.Jet.OLEDB.4.0" & _
"Data Source=c:\somepath\mydb.mdb;" & _
"Jet Oledb:system database=mysystem.mdw;", _
"Admin", "" "
oConn.Open strconn
%>
Note: When using the 4.0 OLE DB Provider provider driver, remember to convert the MDB and MDW to the 4.0 database format.
If the MDB is setting a password, use the following connection string.
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0" & _
"Data Source=c:\somepath\mydb.mdb;" & _
"Jet oledb:database Password=mydbpassword;", _
"Admin", "" "
If the MDB is located on the network and is shared, use the following connection string.
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 OLE DB Provider for Microsoft jet to access the Excel spreadsheet.
<%
Dim Oconn,strconn
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 strconn
%>
Description: Here the Hdr=yes means that the provider accesses the Excel spreadsheet without adding the first row of data to the dataset, and when Hdr=no means that the provider accesses the Excel spreadsheet when the action is exactly the opposite of what is described above.
7 OLE DB Provider for ODBC Databases
Accessing the MS Access database
<%
Dim Oconn,strconn
Set oconn=server.createobject ("ADODB. Connection ")