袖珍数据库连接查询手册
2024-07-21 02:10:52
供稿:网友
本文来源于网页设计爱好者web开发社区http://www.html.org.cn收集整理,欢迎访问。下面的资料可能不太全,但是可以用来做平时的资料查询用的哦,希望能够帮上大家的忙,呵呵。
下面将简单介绍一下几种ado连接方式:odbc dsn,odbc dsn-less,
ole db provider,和"ms remote" provider.
1。odbc dsn连接
i.dsn
oconn.open "dsn=advworks;" & _
"uid=admin;" & _
"pwd=;"
注意:从mdac2.1开始就不能够在使用这样的方式了,就是只把dsn文件名放在connectstring中
你必须同时使用dsn,uid,pwd标志。例如下面的方式在mdac 2.1中将会出错:
oconn.open "advworks"
ii.file dsn
oconn.open "filedsn=/somepath/mydb.dsn;" & _
"uid=admin;" & _
"pwd=;"
iii.odbc dsn-less connections
a)odbc text driver
oconn.open _
"driver={microsoft text driver (*.txt; *.csv)};" & _
"dbq=/somepath/;" & _
"extensions=asc,csv,tab,txt;" & _
"persist security info=false"
注意:需要在sql语句中指定使用到的文件名。例如:
ors.open "select * from customer.csv", _
oconn, adopenstatic, adlockreadonly, adcmdtext
b)odbc driver for access
i)普通安全模式:
oconn.open _
"driver={microsoft access driver (*.mdb)};" & _
"dbq=/somepath/mydb.mdb;" & _
"uid=admin;" & _
"pwd=;"
ii)如果使用了system database:
oconn.open _
"driver={microsoft access driver (*.mdb)};" & _
"dbq=/somepath/mydb.mdb;" & _
"systemdb=/somepath/mydb.mdw;", _
"admin", ""
c)odbc driver for sql server
i)普通安全模式
oconn.open "driver={sql server};" & _
"server=carl2;" & _
"database=pubs;" & _
"uid=sa;" & _
"pwd=;"
ii)使用信任安全模式:
oconn.open "driver={sql server};" & _
"server=carl2;" & _
"database=pubs;" & _
"uid=;" & _
"pwd=;"
注意:要使用空白的uid和pwd
d)odbc driver for oracle
i)使用现有的oracle odbc driver from microsoft:
oconn.open _
"driver={microsoft odbc for oracle};" & _
"server=oracleserver.world;" & _
"uid=demo;" & _
"pwd=demo;"
ii)使用老版本的oracle odbc driver from microsoft:
oconn.open _
"driver={microsoft odbc driver for oracle};" & _
"connectstring=oracleserver.world;" & _
"uid=demo;" & _
"pwd=demo;"
iiii)使用微软的ole db data link connections方式data link file (udl)
a)使用绝对路径
oconn.open "file name=/somepath/pubs.udl;"
b)使用相对路径
oconn.open "file name=pubs.udl;"
v)ole db provider connections方式
a)ole db provider for odbc databases
i)access (jet):
oconn.open _
"provider=msdasql;" & _
"driver={microsoft access driver (*.mdb)};" & _
"dbq=/somepath/mydb.mdb;" & _
"uid=admin;" & _
"pwd=;"
ii)sql server:
oconn.open _
"provider=msdasql;" & _
"driver={sql server};" & _
"server=carl2;" & _
"database=pubs;" & _
"uid=sa;" & _
"pwd=;"
b)ole db provider for microsoft jet (access)
i)普通安全模式:
oconn.open _
"provider=microsoft.jet.oledb.4.0;" & _
"data source=/somepath/mydb.mdb;" & _
"user id=admin;" & _
"password=;"
ii)如果使用了system database:
oconn.open _
"provider=microsoft.jet.oledb.4.0;" & _
"data source=/somepath/mydb.mdb;" & _
"jet oledb:system database=system.mdw;", _
"admin", ""
注意:当使用ole db provider4.0版本是,需要把mdb和mdw文件转换成4.0的数据库格式
iii)如果mdb需要一个数据库密码的话:
oconn.open _
"provider=microsoft.jet.oledb.4.0;" & _
"data source=/somepath/mydb.mdb;" & _
"jet oledb:database password=mydbpassword;", _
"admin", ""
c)ole db provider for excel spreadsheet:
oconn.open _
"provider=microsoft.jet.oledb.4.0;" & _
"data source=/somepath/expenses.xls;" & _
"extended properties=""excel 8.0;hdr=yes;"";"
注意: "hdr=yes"表示在第一行中是行标题,在provider中将不把第一行包括入recordset中
d)ole db provider for sql server
i)普通安全模式:
oconn.open "provider=sqloledb;" & _
"network library=dbmssocn;" & _
"data source=carl2;" & _
"initial catalog=pubs;" & _
"user id=sa;" & _
"password=;"
ii)使用信任安全模式:
oconn.open "provider=sqloledb;" & _
network library=dbmssocn;" & _
"data source=carl2;" & _
"initial catalog=pubs;" & _
"trusted_connection=yes;"
注意:"network library=dbmssocn"声明ole db使用tcp/ip替代named pipes.
e)ole db provider for oracle
oconn.open "provider=msdaora;" & _
"data source=oracleserver.world;" & _
"user id=sa;" & _
"password=;"
(vi)remote ole db provider connections方式(就是我一直在研究的rds方式哦,呵呵。):
a)ms remote - access (jet)
i)odbc dsn:
oconn.open "remote server=http://carl2;" & _
"remote provider=msdasql;" & _
"dsn=advworks;" & _
"uid=admin" & _
"pwd=;"
ii)ole db provider:
oconn.open "provider=ms remote;" & _
"remote server=http://carl2;" & _
"remote provider=microsoft.jet.oledb.4.0;" & _
"data source=/somepath/mydb.mdb;", _
"admin", ""
iii)ole db provider自定义事务对象
oconn.open "provider=ms remote;" & _
"remote server=http://carl2;" & _
"handler=msdfmap.handler;" & _
"data source=myadvworksoledbconnecttag;"
b)ms remote - sql server
i)odbc dsn:
oconn.open "remote server=http://carl2;" & _
"remote provider=msdasql;" & _
"network library=dbmssocn;" & _
"dsn=pubs;" & _
"uid=sa" & _
"pwd=;"
ii)ole db provider
oconn.open "provider=ms remote;" & _
"remote server=http://carl2;" & _
"remote provider=sqloledb;" & _
"network library=dbmssocn;" & _
"data source=carl2;" & _
"initial catalog=pubs;" & _
"user id=sa;" & _
"password=;"