ASP連接Access數(shù)據(jù)庫(kù)的幾種方法
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ù)庫(kù)代碼
<% Const DataBaseType=1 If DataBaseType=0 then DBPath="/jb51/news.asp" SqlNowString = "Now()" ystr=true nstr=false suiji="rnd(id)" Else '如果是SQL數(shù)據(jù)庫(kù),請(qǐng)認(rèn)真修改好以下數(shù)據(jù)庫(kù)選項(xiàng) DataServer = "wwwjb51net" '數(shù)據(jù)庫(kù)服務(wù)器IP DataUser = "jb51net" '訪問(wèn)數(shù)據(jù)庫(kù)用戶名 DataBaseName = "jb51net" '數(shù)據(jù)庫(kù)名稱 DataBasePsw = "密碼" '訪問(wèn)數(shù)據(jù)庫(kù)密碼 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ù)庫(kù)連接出錯(cuò),請(qǐng)檢查Conn.asp文件中的數(shù)據(jù)庫(kù)參數(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ù)庫(kù)的幾種方法的文章就介紹到這了,更多相關(guān)ASP連接Access數(shù)據(jù)庫(kù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
如何保持?jǐn)?shù)據(jù)庫(kù)輸出格式不變
如何保持?jǐn)?shù)據(jù)庫(kù)輸出格式不變...2007-02-02asp Fix、Int、Round、CInt函數(shù)使用說(shuō)明
Fix(number) 和 Int(number) 都是返回?cái)?shù)字的整數(shù)部分,Round(number, numdecimalplaces),第二個(gè)參數(shù)表示從小數(shù)點(diǎn)右邊第幾位開始實(shí)行四舍五入,可以省略,默認(rèn)是0,即四舍五入返回整數(shù)2011-05-05ASP中Web頁(yè)面間的數(shù)據(jù)傳遞方式
ASP中Web頁(yè)面間的數(shù)據(jù)傳遞方式...2006-06-06asp實(shí)現(xiàn)無(wú)限級(jí)分類的方法js版
asp實(shí)現(xiàn)無(wú)限級(jí)分類的方法js版...2006-06-06.NET Framework各版本(.NET2.0 3.0 3.5 4.0)區(qū)別
本文主要介紹.NET各個(gè)版本之間的區(qū)別,以幫助新手朋友選擇適合的.NET Framework的版本進(jìn)行開發(fā)。2016-03-03