相思资源网 Design By www.200059.com

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数据库,在线压缩access数据库

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“深入浅析ASP在线压缩access数据库的方法”

暂无深入浅析ASP在线压缩access数据库的方法的评论...