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 编辑过 |
关键字查询
相关文章
正在查询... |