Access數(shù)據(jù)庫(kù)在線壓縮的方法

字號(hào):


    Access數(shù)據(jù)庫(kù)在線壓縮的方法
    如果在 Access 數(shù)據(jù)庫(kù)中刪除數(shù)據(jù)或?qū)ο?,或者?Access 項(xiàng)目中刪除對(duì)象,Access 數(shù)據(jù)庫(kù)或 Access 項(xiàng)目可能會(huì)產(chǎn)生碎片并會(huì)降低磁盤空間的使用效率。壓縮 Access 數(shù)據(jù)庫(kù)或Access項(xiàng)目實(shí)際上是復(fù)制該文件,并重新組織文件在磁盤上的存儲(chǔ)方式。壓縮同時(shí)優(yōu)化了 Access 數(shù)據(jù)庫(kù)和 Access 項(xiàng)目的性能。
    所以我們?cè)趯?duì)日益增大的數(shù)據(jù)庫(kù)導(dǎo)致的ASP程序慢得無(wú)法忍受的時(shí)候,就想到了要壓縮他。但常規(guī)的做法把他下載到本地然后用MSaccess來(lái)完成壓縮操作,然后再上傳!
    需要注意的是:本程序其實(shí)是通過(guò)FSO權(quán)限和JET引擎連接,因此在使用之前請(qǐng)確認(rèn)你的服務(wù)器支持FSO(filesystemobject)權(quán)限并安裝的ACCESS最新驅(qū)動(dòng)!從安全出發(fā),請(qǐng)?jiān)趬嚎s之前備份原始數(shù)據(jù)庫(kù)!已經(jīng)測(cè)試通過(guò)的運(yùn)行環(huán)境:
    WIN98SE+PWS、WIN2000+IIS5.0
    下面是我整理后的源代碼,復(fù)制另存為compact.asp并上傳到數(shù)據(jù)庫(kù)所在目錄即可正常使用。
    <html>
    <head>
    <title>ACCESS數(shù)據(jù)庫(kù)壓縮程序</title>
    </head>
    <body bgcolor="e0f8ef">
    <div>
    <div><font color="#3300FF">
    <b><font size="5">通用ACCESS數(shù)據(jù)庫(kù)在線壓縮程序</font></b></font><br>
    </div>
    <div><br>
    本程序其實(shí)是通過(guò)FSO權(quán)限和JET引擎連接,
    因此在使用之前請(qǐng)確認(rèn)你的服務(wù)器支持FSO
    (filesystemobject)權(quán)限并安裝的ACCESS最新驅(qū)動(dòng)!
    從安全出發(fā),請(qǐng)?jiān)趬嚎s之前備份原始數(shù)據(jù)庫(kù)!
    </div><br>
    <div>運(yùn)行環(huán)境:在WIN98SE+PWS、WIN2000+IIS5.0 <br>
    <%
    Const JET_3X = 4
    Function CompactDB(dbPath, boolIs97)
    Dim fso, Engine, strDBPath
    strDBPath = left(dbPath,instrrev(DBPath,""))
    Set fso = CreateObject("Scripting.FileSystemObject")
    If fso.FileExists(dbPath) Then
    Set Engine = CreateObject("JRO.JetEngine")
    If boolIs97 = "True" Then
    Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath, _
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb;" _
    & "Jet OLEDB:Engine Type=" & JET_3X
    Else
    Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath, _
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb"
    End If
    fso.CopyFile strDBPath & "temp.mdb",dbpath
    fso.DeleteFile(strDBPath & "temp.mdb")
    Set fso = nothing
    Set Engine = nothing
    CompactDB = "你的數(shù)據(jù)庫(kù), " & dbpath & ", 已經(jīng)被壓縮" & vbCrLf
    Else
    CompactDB = "你輸入的數(shù)據(jù)庫(kù)路徑或名稱未找到,請(qǐng)重試" & vbCrLf
    End If
    End Function
    %>
    </div>
    </div>
    <form name="compact" method="post" action="compact.asp">
    <div>
    <font size="2"><b><font color="#FF0000">
    壓縮選項(xiàng),請(qǐng)仔細(xì)填寫!</font></b><br>
    <br>
    輸入數(shù)據(jù)庫(kù)全稱:
    <input type="text" name="dbpath">
    (包括擴(kuò)展名,如MDB、ASA、ASP等)<br>
    <br>
    <input type="checkbox" name="boolIs97" value="True">
    檢查是否為ACCESS97數(shù)據(jù)庫(kù)<br>
    (默認(rèn)為ACCESS2000的數(shù)據(jù)庫(kù))<br>
    <br>
    <input type="submit" name="submit" value="確認(rèn)壓縮">
    </font></div>
    </form>
    <div><font size="2">
    <%
    Dim dbpath,boolIs97
    dbpath = request("dbpath")
    boolIs97 = request("boolIs97")
    If dbparesponse.write(CompactDB(dbpath,boolIs97))
    End If
    %>
    <br>
    </font></div></body></html>th <> "" Then
    dbpath = server.mappath(dbpath)