'==========注意=============================================== ' 1、網(wǎng)站所在文件夾的名字不能為“root” ' 2、網(wǎng)站所在文件夾的名字,物理路徑中不允許出現(xiàn)重復(fù)此文件夾名,如F:/t/t,t為網(wǎng)站所在文件夾名,這種情況會(huì)出錯(cuò) '============================================================= Dim dbPath,dbName,Db,ConnStr,WebSiteFolderName on error resume next
WebSiteFolderName="WeldSiteBuilder" dbPath = "_sitedata/" '注意是反斜杠,且只有末尾有 dbName = "acteedata.mdb" '數(shù)據(jù)庫(kù)名稱 Db=GetSitePhysicalPath(WebSiteFolderName) & dbPath & dbName 'response.Write("當(dāng)前數(shù)據(jù)庫(kù)物理路徑:"&server.mappath(db)) 'response.Write("<hr>") 'response.Write("當(dāng)前請(qǐng)求訪問的頁(yè)面路徑:"&request.ServerVariables("URL")) 'response.Write("<hr>") 'response.Write("當(dāng)前站點(diǎn)的根路徑:"&request.ServerVariables("APPL_PHYSICAL_PATH")) 'response.Write("<hr>") 'response.Write("當(dāng)前站點(diǎn)的路徑狀況:"&request.ServerVariables("APPL_MD_PATH")) 'response.Write(db) 'response.End() '====================== Set conn=Server.CreateObject("ADODB.Connection") ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Db Conn.Open ConnStr If Err Then Err.Clear Set Conn = Nothing Response.Write "數(shù)據(jù)庫(kù)連接錯(cuò)誤!" Response.End End If
Sub CloseConn() conn.close set conn=nothing end Sub
'獲取網(wǎng)站所在目錄的絕對(duì)路徑(帶“/”號(hào)) Function GetSitePhysicalPath(WSFN) dim APPL_MD_PATH,APPL_MD_PATHArray,Path,WSPP WSPP=request.ServerVariables("APPL_PHYSICAL_PATH")'默認(rèn)網(wǎng)站是在根目錄下運(yùn)行
APPL_MD_PATH=request.ServerVariables("APPL_MD_PATH") APPL_MD_PATHArray=split(APPL_MD_PATH,"/") Path=APPL_MD_PATHArray(UBound(APPL_MD_PATHArray)) if UCase(Path)="ROOT" then '判斷網(wǎng)站是不是在獨(dú)立的應(yīng)用程序下運(yùn)行 '再判斷網(wǎng)站是不是在某個(gè)文件夾下運(yùn)行 if InStr(WSPP,WSFN)=0 then '網(wǎng)站在根目錄下的一個(gè)文件夾下運(yùn)行 '根據(jù)受訪頁(yè)面的地址拼出網(wǎng)站所在文件夾的地址 dim CurrentUrl,NameArray CurrentUrl=request.ServerVariables("URL") NameArray=split(CurrentUrl,"/") for i=LBound(NameArray) to UBound(NameArray) if UCase(NameArray(i))=UCase(WSFN) then for j=0 to i WSPP=WSPP+NameArray(j)+"/" next exit for end if next else '表明網(wǎng)站是在根目錄下運(yùn)行 '什么都不必做,返回值已經(jīng)初始化了 end if else '表明網(wǎng)站是在虛擬目錄下運(yùn)行 '什么也不做,返回值已經(jīng)初始化了 end if WSPP=replace(WSPP,"http://","/") GetSitePhysicalPath=WSPP End Function