四種經常使用的access鏈接方式

整理出四種經常使用的access鏈接方式,固然,第1種這是最經常使用的(推薦使用)。
1. 
set dbconnection=Server.CreateOBJECT("ADODB.CONNECTION") 
DBPath = Server.MapPath("customer.mdb") //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 2881064151 
4. 
建odbc源xxx (該項僅適用於獨立主機用戶,虛擬主機不支持數據源)
set conn=server.createobject("Adodb.connection") 
conn.open "DSN=xxx;UID=;PWD=;Database=customersql

SQL數據庫 
conn="Driver={SQL Server};Server=數據庫服務器名稱或者數據庫IP地址;Database=數據庫名;UID=登陸用戶名;PWD=登陸密碼" 
Access數據庫 
conn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&server.mappath("數據庫名.mdb")數據庫

相關文章
相關標籤/搜索