日期:2012-06-21  浏览次数:20829 次

(接上篇)

二 二、接下来讲使用OLE DB来连接数据库的例子。

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

● 标准的也是常用的访问方式。

<%

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

%>

● 假如是一个工作组的系统数据库,那么连接字符串如下。

<%

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

%>

注意:在使用4.0 OLE DB Provider 提供者的驱动程序时,要记得把MDB和MDW转换成the 4.0 database格式。

● 如果MDB是设置密码的话,那么使用如下连接字符串。

oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _

          "Data Source=c:\somepath\mydb.mdb;" & _

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

          "admin", ""

● 如果MDB是位于网络中并且是共享的话,那么使用如下连接字符串。

oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _

      "Data Source=\\myServer\myShare\myPath\myDb.mdb;

● 如果要想使用专有的方式来访问数据库,那么使用如下连接字符串。

oConn.Mode = adModeShareExclusive

oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _

          "Data Source=c:\somepath\myDb.mdb;" & _

          "User Id=admin;Password=;"

6)使用OLE DB Provider for Microsoft Jet来访问Excel电子数据表。

<%

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;""