连接数据库查询手册
下面将简单介绍一下几种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=somepathmydb.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=somepathmydb.mdb;" & _
"Uid=Admin;" & _
"Pwd=;"
ii)如果使用了System database:
oConn.Open _
"Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=somepathmydb.mdb;" & _
"SystemDB=somepathmydb.mdw;", _
"admin", ""
c)ODBC Driver for SQL Server
i)普通安全模式
oConn.Open "Driver={SQL Server};" & _
"Server=carl2;" & _
"Database=pubs;" & _
"Uid=sa;" & _
补充:asp教程,数据库相关