第一种 – 这种方法用在ACCESS中最多
代码如下 | 复制代码 |
dim conn,strconn strconn = “DRIVER=Microsoft Access Driver (*.mdb);DBQ=” & Server.MapPath(“aspfree.mdb”) set conn = server.createobject(“adodb.connection”) conn.open strconn |
第二种-这种方法用在SQL SERVER中多
代码如下 | 复制代码 |
strconn = “Driver={SQL erver};Description=sqldemo;SERVER=127.0.0.1;UID=LoginID;&_ PWD=Password;DATABASE=Database_Name set conn = server.createobject(“adodb.connection”) conn.open strconn |
第三种
代码如下 | 复制代码 |
strconn=”Driver={MicrosoftAccessDriver(*.mdb)};” &_ “DBQ=F:Inetpubwwwrootsomedirdb1.mdb;DefaultDir=f:Inetpubwwwrootsomedir; &_ uid=LoginID;” &_ “pwd=Password;DriverId=25;FIL=MSAccess;” set conn = server.createobject(“adodb.connection”) conn.open strconn |
第四种运用系统数据源
代码如下 | 复制代码 |
The following uses a Data Source Name: set conn = server.createobject(“adodb.connection”) conn.open “Example” |
第五种运用ODBC数据源,前提是你必须在控制面板的ODBC中设置数据源
代码如下 | 复制代码 |
set rs = server.createobject(“adodb.recordset”) rs.open “tblname”, “DSNName”, 3, 3 1. set dbconnection=Server.CREATEOBJECT(“ADODB.CONNECTION”) DBPath = Server.MapPath(“customer.mdb”) dbconnection.Open “driver={Microsoft Access Driver (*.mdb)};dbq=” & DBPath SQL=”select * from auth where id=”" & user_id &”"” SET uplist=dbconnection.EXECUTE(SQL) 2. set dbconnection=Server.CreateObject(“ADODB.Connection”) DBPath = Server.MapPath(“customer.mdb”) dbconnection.Open “provider=microsoft.jet.oledb.4.0;data source=”&dbpath SQL=”select * from auth where id=”" & user_id &”"” SET uplist=dbconnection.EXECUTE(SQL) 3. DBPath = Server.MapPath(“customer.mdb”) set session(“rs”)=Server.CreateObject(“ADODB.Recordset”) “ rs=Server.CreateObject(“ADODB.Recordset”) connstr=”provider=microsoft.jet.oledb.4.0;data source=”&dbpath SQL=”select * from auth where id=”" & user_id &”"” session(“rs”).Open sql,connstr,1,3 4. 建odbc源xxx set conn=server.createobject(“Adodb.connection”) conn.open “DSN=xxx;UID=;PWD=;Database=customer 连 |
接mysql数据库
'测试读取MySql数据库的内容
代码如下 | 复制代码 |
strconnection="driver={mysql odbc 3.51 driver};database=weste_net;server=localhost;uid=root;password=" '无需配置dsn set adodataconn = server.createobject("adodb.connection") adodataconn.open strconnection |
时间: 2024-09-11 14:43:27