ASP代码:在线压缩Access数据库 |
时间:2006-05-26 00:00:00 来源:TIANZI.ORG 作者:天子 阅读:1946次 |
|
|
网站用的是Access数据库,时间长了数据库很臃肿,就需要对Access数据库进行压缩减肥, 将下面代码保存为Compact.asp然后上传,即可在线进行Access数据库的压缩了. 注:代码已经本人测试无误.
<% option explicit Const JET_3X = 4
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")
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 fso.CopyFile strDBPath & "temp.mdb",dbpath fso.DeleteFile(strDBPath & "temp.mdb") Set fso = nothing Set Engine = nothing CompactDB = "你的数据库 " & dbpath & " 已经压缩完毕" & vbCrLf Else CompactDB = "The database name or path has not been found. Try Again" & vbCrLf End If
End Function %> <html><head><title>数据库在线压缩 - tianzi.org</title></head><body> <p align="center"> <form action=compact.asp> 请输入你的数据库路径包括名字.<br><br> <input type="text" name="dbpath"><br><br> <input type="checkbox" name="boolIs97" value="True"> 检查如果是 Access 97 <br><i> (默认为 Access 2000)</i><br><br> <input type="submit"> <form> <br><br> <% Dim dbpath,boolIs97 dbpath = request("dbpath") boolIs97 = request("boolIs97")
If dbpath <> "" Then dbpath = server.mappath(dbpath) response.write(CompactDB(dbpath,boolIs97)) End If %> </p></body></html> |
|
|
|
|
|