我帮忙转载过来了,省的麻烦
ASP实现在线压缩ACCESS数据库的代码
关键字: ASP实现在线压缩ACCESS数据库的代码
<!--data.asp-->
<%
dim action,db
db=需要进行压缩的ACCESS数据库相对地址,(如:db="../Databackup/Data_Backup.mdb")
action=Trim(request("action"))
Select Case action
Case "CompressData" '压缩数据
Call CompressData()
end Select
'====================压缩数据库 =========================
sub CompressData()
%>
<html>
<body bgcolor="#c4d8ed">
<table border="0" cellspacing="1" cellpadding="5" height="1" align="center" width="100%" class="adminTableBorder">
<tr>
<td class="adminTableTitle" height="25" align="center" valign="middle"><b>压缩数据库</b></td>
</tr>
<form action="data.asp?action=CompressData" method="post" name="CompressDataForm">
<tr>
<td class="adminTd" height=25><b>注意:</b><br>输入数据库所在相对路径,并且输入数据库名称(正在使用中数据库不能压缩,请选择备份数据库进行压缩操作) </td>
</tr>
<tr>
<td class="adminTd">压缩数据库:<input type="text" name="dbpath" value="<%=db%>">
<input type="submit" class="button" value="开始压缩"></td>
</tr>
<tr>
<td class="adminTd"><input type="checkbox" class="checkbox" name="boolIs97" value="True">如果使用 Access 97 数据库请选择(默认为 Access 2000 数据库)<br><br></td>
</tr>
<form>
</table>
<%
dim dbpath,boolIs97
dbpath = request("dbpath")
boolIs97 = request("boolIs97")
If dbpath <> "" Then
dbpath = server.mappath(dbpath)
response.write(CompactDB(dbpath,boolIs97))
End If
response.Write("</body></html>")
end sub
'=====================压缩参数=========================
Function CompactDB(dbPath, boolIs97)
Dim fso, Engine, strDBPath,JET_3X
dbPath = Replace(dbPath,chr(0),"")
strDBPath = left(dbPath,instrrev(DBPath,"\"))
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(dbPath) Then
fso.CopyFile dbpath,strDBPath & "temp.mdb"
Set Engine = CreateObject("JRO.JetEngine")
If boolIs97 = "True" Then
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp1.mdb;" _
& "Jet OLEDB:Engine Type=" & JET_3X
Else
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp1.mdb"
End If
fso.CopyFile strDBPath & "temp1.mdb",dbpath
fso.DeleteFile(strDBPath & "temp.mdb")
fso.DeleteFile(strDBPath & "temp1.mdb")
Set fso = nothing
Set Engine = nothing
CompactDB = "<span style='font-size:14px;color:#135294;'>你的数据库: " & dbpath & ", 已经压缩成功!</span>" & vbCrLf
Else
CompactDB = "<span style='font-size:14px;color:#135294;'>数据库名称或路径不正确. 请重试!</span>" & vbCrLf
End If
End Function
%>