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ì)填寫(xiě)!</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)