[转]ASP在线压缩ACCESS数据库
作者:cmscn 日期:2009-08-13
使用ACCESS作数据库的站长会发现,随着时间的增长你的数据库会越来越大,甚至你删除数据数据库不会变小还会变大,其实在access数据库里还有好几个隐藏表!有次一个人让我给他看看网站,网站占用空间500多M,他压缩后发给我后是50M,但当我给压缩数据库后发现,他的网站总占用空间不到10M...几十倍的差距。用下面的代码可以实现对access数据库的压缩,不会损伤数据库的任何数据,可安全使用
<%
path=server.mappath("mydb.mdb")
is97=true '这个参数决定调用方法的参数不同,若是97数据库请设为true,否则为false
Response.Write PA_CompactDB(request.querystring("path"), is97)
Function PA_CompactDB(m_strDBFile, m_bIsAccess97)
Dim objFSO, ofileb,ofilea,objEngine, strDBFileB,JET_3X,sizestring
Dim bHasError
On Error Resume Next
bHasError = False
strDBFileA = Server.MapPath(m_strDBFile)
strDBFileB = left(strDBFileA,InStrRev(strDBFileA,"\"))
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strDBFileA) Then
Set objEngine = CreateObject("JRO.JetEngine")
If Err.Number<>0 Then
PA_CompactDB = "Error:" & Err.Description
Err.Clear
Else
set ofileb=objFSO.getfile(strDBFileA)
sizestring="Before Compacted,Filesize is "&(ofileb.size/1024)&"KB;<br>"
If m_bIsAccess97 = True Then
objEngine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBFileA, _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBFileB & "_temp.mdb;" _
& "Jet OLEDB:objEngine Type=" & JET_3X
Else
objEngine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBFileA, _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBFileB & "_temp.mdb"
End If
objFSO.CopyFile strDBFileB & "_temp.mdb",strDBFileA
objFSO.DeleteFile(strDBFileB & "_temp.mdb")
Set objEngine = nothing
set ofilea=objFSO.getfile(strDBFileA)
sizestring=sizestring&"After Compacted,Filesize is "&(ofilea.size/1024)&"KB!<br>"
PA_CompactDB ="Your Database(" & strDBFileA & ") has benn compacted successfully!<br>"&sizestring
End If
Else
PA_CompactDB = "Your database path is wrong!"
End If
Set objFSO = nothing
Set ofileb = nothing
Set ofilea = nothing
on Error Goto 0
End Function
%>
评论: 0 | 引用: 0 | 查看次数: 420
发表评论