asp在线压缩access数据库原理很简单:利用jro.jetengine的压缩功能建立一个新的数据库文件,然后把原来的删掉、替换!既然这样,压缩程序只需几行就ok了!
把下面的代码保存为**.asp,数据库文件(db.md)放在相同目录下,执行asp搞定!
<% olddb = server.mappath("db.mdb") '更改数据库地址 newdb = server.mappath("db_new.mdb") '生成临时文件 set fso = server.createobject("scripting.filesystemobject") set engine = server.createobject("jro.jetengine") prov = "provider=microsoft.jet.oledb.4.0;data source=" engine.compactdatabase prov & olddb, prov & newdb set engine = nothing fso.deletefile olddb '删除临时文件 fso.movefile newdb, olddb set fso = nothing response.write "ok" %>
下面是一个asp在线压缩access数据库的封装函数
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") on error resume next 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 if err then response.write "<script language='javascript'>alert('无法识别数据库类型.');history.go(-1);</script>" response.end end if fso.copyfile strdbpath & "temp.mdb",dbpath fso.deletefile(strdbpath & "temp.mdb") set fso = nothing set engine = nothing compactdb = "<script>alert('压缩成功!');javascript:history.go(-1);</script>" else compactdb = "<script>alert('找不到数据库!\n请检查数据库路径是否输入错误!');history.back();</script>" end if end function
总结
到此这篇关于asp在线压缩access数据库的方法的文章就介绍到这了,更多相关asp在线压缩access数据库内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!