佳木斯湛栽影视文化发展公司

主頁 > 知識(shí)庫 > ASP連接Access數(shù)據(jù)庫的幾種方法

ASP連接Access數(shù)據(jù)庫的幾種方法

熱門標(biāo)簽:Linux服務(wù)器 Mysql連接數(shù)設(shè)置 銀行業(yè)務(wù) 服務(wù)器配置 電子圍欄 科大訊飛語音識(shí)別系統(tǒng) 阿里云 團(tuán)購網(wǎng)站

1. 相對(duì)與比較老的環(huán)境,建議使用第二個(gè)

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.win2003以上的機(jī)器,建議用此方法,效率更高

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 

5、附上一個(gè)經(jīng)常用的sqlserver與access通用的連接數(shù)據(jù)庫代碼

% 
Const DataBaseType=1 
If DataBaseType=0 then 
DBPath="/jb51/news.asp" 
SqlNowString = "Now()" 
ystr=true 
nstr=false 
suiji="rnd(id)" 
Else 
'如果是SQL數(shù)據(jù)庫,請(qǐng)認(rèn)真修改好以下數(shù)據(jù)庫選項(xiàng) 
DataServer = "wwwjb51net" '數(shù)據(jù)庫服務(wù)器IP 
DataUser = "jb51net" '訪問數(shù)據(jù)庫用戶名 
DataBaseName = "jb51net" '數(shù)據(jù)庫名稱 
DataBasePsw = "密碼" '訪問數(shù)據(jù)庫密碼 
SqlNowString = "getdate()" 
ystr=1 
nstr=0 
suiji="newid()" 
End if 
On Error Resume Next 
If DataBaseType = 1 Then 
ConnStr="driver={SQL Server};server="dataserver";UID="datauser";PWD="databasepsw";Database="databasename 
Else 
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="  Server.MapPath(DBPath) 
End If 
Set conn = Server.CreateObject("ADODB.Connection") 
conn.open ConnStr 
If Err Then Err.Clear:Set conn = Nothing:Response.Write "數(shù)據(jù)庫連接出錯(cuò),請(qǐng)檢查Conn.asp文件中的數(shù)據(jù)庫參數(shù)設(shè)置。":Response.End 
%> 

完整測(cè)試代碼

Microsoft Access Driver

%
db="1.mdb"
dim conn,db 
dim connstr 
on error resume next 
connstr="DBQ="+server.mappath(""db"")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};" 
set conn=server.createobject("ADODB.CONNECTION") 
if err then 
err.clear 
else 
conn.open connstr 
end if 

t=timer()
for i=0 to 1000
	Set Res=Conn.Execute("select (Select top 1 name from [aa] where id=1) as oldname,(Select top 1 name from [aa] where id=2) as newname from [aa]")
	aa=Res("oldname")
	bb=Res("newname")
	Res.close
	set Res=nothing
next
response.write "用時(shí):"(timer()-t)
%> 

microsoft.jet.oledb.4.0

%
db="1.mdb"
dim conn,db 
dim connstr 
on error resume next 
connstr="provider=microsoft.jet.oledb.4.0;data source="+server.mappath(""db"")
set conn=server.createobject("ADODB.CONNECTION") 
if err then 
err.clear 
else 
conn.open connstr 
end if 

t=timer()
for i=0 to 1000
	Set Res=Conn.Execute("select (Select top 1 name from [aa] where id=1) as oldname,(Select top 1 name from [aa] where id=2) as newname from [aa]")
	aa=Res("oldname")
	bb=Res("newname")
	Res.close
	set Res=nothing
next
response.write "用時(shí):"(timer()-t)
%> 

到此這篇關(guān)于ASP連接Access數(shù)據(jù)庫的幾種方法的文章就介紹到這了,更多相關(guān)ASP連接Access數(shù)據(jù)庫內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • 用ASP實(shí)現(xiàn)在線壓縮與解壓縮功能代碼
  • 用ASP.Net實(shí)現(xiàn)文件的在線壓縮和解壓縮
  • ASP 連接Access數(shù)據(jù)庫的登陸系統(tǒng)
  • asp連接access、sql數(shù)據(jù)庫代碼及數(shù)據(jù)庫操作代碼
  • access數(shù)據(jù)庫的一些少用操作,ASP,創(chuàng)建數(shù)據(jù)庫文件,創(chuàng)建表,創(chuàng)建字段,ADOX
  • 深入淺析ASP在線壓縮access數(shù)據(jù)庫的方法

標(biāo)簽:大理 棗莊 衡水 萍鄉(xiāng) 廣元 江蘇 蚌埠 衢州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP連接Access數(shù)據(jù)庫的幾種方法》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    崇州市| 石河子市| 庐江县| 祥云县| 凌海市| 郎溪县| 巴里| 水城县| 马龙县| 淮南市| 洛扎县| 泗洪县| 绥江县| 英吉沙县| 铜川市| 达尔| 开鲁县| 江阴市| 萨迦县| 雷山县| 房产| 兴海县| 黄梅县| 吉水县| 沭阳县| 兰坪| 乐都县| 喀什市| 醴陵市| 玉树县| 靖西县| 双江| 海晏县| 连城县| 同德县| 卢湾区| 耒阳市| 秭归县| 郧西县| 汨罗市| 云梦县|