ASP在線壓縮ACCESS數(shù)據(jù)庫(kù)
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
使用access作數(shù)據(jù)庫(kù)的站長(zhǎng)會(huì)發(fā)現(xiàn),隨著時(shí)間的增長(zhǎng)你的數(shù)據(jù)庫(kù)會(huì)越來(lái)越大,甚至你刪除數(shù)據(jù)數(shù)據(jù)庫(kù)不會(huì)變小還會(huì)變大,其實(shí)在access數(shù)據(jù)庫(kù)里還有好幾個(gè)隱藏表!有次一個(gè)人讓我給他看看網(wǎng)站,網(wǎng)站占用空間500多m,他壓縮后發(fā)給我后是50m,但當(dāng)我給壓縮數(shù)據(jù)庫(kù)后發(fā)現(xiàn),他的網(wǎng)站總占用空間不到10m...幾十倍的差距。用下面的代碼可以實(shí)現(xiàn)對(duì)access數(shù)據(jù)庫(kù)的壓縮,不會(huì)損傷數(shù)據(jù)庫(kù)的任何數(shù)據(jù),可安全使用
[br]<% [br]path=server.mappath("mydb.mdb") [br]is97=true '這個(gè)參數(shù)決定調(diào)用方法的參數(shù)不同,若是97數(shù)據(jù)庫(kù)請(qǐng)?jiān)O(shè)為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 編輯過(guò) |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |