ASP在線壓縮ACCESS數據庫
當前位置:點晴教程→知識管理交流
→『 技術文檔交流 』
使用access作數據庫的站長會發現,隨著時間的增長你的數據庫會越來越大,甚至你刪除數據數據庫不會變小還會變大,其實在access數據庫里還有好幾個隱藏表!有次一個人讓我給他看看網站,網站占用空間500多m,他壓縮后發給我后是50m,但當我給壓縮數據庫后發現,他的網站總占用空間不到10m...幾十倍的差距。用下面的代碼可以實現對access數據庫的壓縮,不會損傷數據庫的任何數據,可安全使用
[br]<% [br]path=server.mappath("mydb.mdb") [br]is97=true '這個參數決定調用方法的參數不同,若是97數據庫請設為true,否則為false [br]response.write pa_compactdb(request.querystring("path"), is97) [br][br][br]function pa_compactdb(m_strdbfile, m_bisaccess97) [br] dim objfso, ofileb,ofilea,objengine, strdbfileb,jet_3x,sizestring [br] dim bhaserror [br] on error resume next [br] bhaserror = false [br] strdbfilea = server.mappath(m_strdbfile) [br] strdbfileb = left(strdbfilea,instrrev(strdbfilea,"\")) [br] set objfso = createobject("scripting.filesystemobject") [br][br] if objfso.fileexists(strdbfilea) then [br] set objengine = createobject("jro.jetengine") [br][br] if err.number<>0 then [br] pa_compactdb = "error:" & err.description [br] err.clear [br] else [br] set ofileb=objfso.getfile(strdbfilea) [br] sizestring="before compacted,filesize is "&(ofileb.size/1024)&"kb; " [br] if m_bisaccess97 = true then [br] objengine.compactdatabase "provider=microsoft.jet.oledb.4.0;data source=" & strdbfilea, _ [br] "provider=microsoft.jet.oledb.4.0;data source=" & strdbfileb & "_temp.mdb;" _ [br] & "jet oledb:objengine type=" & jet_3x [br] else [br] objengine.compactdatabase "provider=microsoft.jet.oledb.4.0;data source=" & strdbfilea, _ [br] "provider=microsoft.jet.oledb.4.0;data source=" & strdbfileb & "_temp.mdb" [br] end if [br][br] objfso.copyfile strdbfileb & "_temp.mdb",strdbfilea [br] objfso.deletefile(strdbfileb & "_temp.mdb") [br] set objengine = nothing [br] set ofilea=objfso.getfile(strdbfilea) [br] sizestring=sizestring&"after compacted,filesize is "&(ofilea.size/1024)&"kb! " [br] pa_compactdb ="your database(" & strdbfilea & ") has benn compacted successfully! "&sizestring [br] end if [br] else [br] pa_compactdb = "your database path is wrong!" [br] end if [br] set objfso = nothing [br] set ofileb = nothing [br] set ofilea = nothing [br] on error goto 0 [br]end function [br]%> 該文章在 2010/7/8 13:53:02 編輯過 |
關鍵字查詢
相關文章
正在查詢... |