<!--#include file="check8.asp"-->
<!--#include file="../Dataname.asp"-->

<%
Const Jet_Conn_Partial = "Provider=Microsoft.Jet.OLEDB.4.0; Data source="
Dim strDatabase, strFolder, strFileName

'################################################# 
'# Edit the following two lines
'# Define the full path to where your database is
fullpath=server.mappath(Request.ServerVariables("SCRIPT_NAME"))
pathshu=instr(fullpath,managerfolder)

strFolder = left(fullpath,pathshu-1) &"data\"

'response.write strFolder&mydataname

'# Enter the name of the database
strDatabase = mydataname
'# Stop editing here
'##################################################

Private Sub dbCompact(strDBFileName)
Dim SourceConn
Dim DestConn
Dim oJetEngine
Dim oFSO

SourceConn = Jet_Conn_Partial & strFolder & strDatabase
DestConn = Jet_Conn_Partial & strFolder & "Temp" & strDatabase

Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
Set oJetEngine = Server.CreateObject("JRO.JetEngine")

With oFSO

If Not .FileExists(strFolder & strDatabase) Then
Response.Write ("没有发现: " & strFolder & strDatabase)
Stop
Else
If .FileExists(strFolder & "Temp" & strDatabase) Then
Response.Write ("Something went wrong last time " _
& "Deleting old database... Please try again")
.DeleteFile (strFolder & "Temp" & strDatabase)
End If
End If
End With

With oJetEngine
.CompactDatabase SourceConn, DestConn
End With

oFSO.DeleteFile strFolder & strDatabase
oFSO.MoveFile strFolder & "Temp" & strDatabase, strFolder& strDatabase

Set oFSO = Nothing
Set oJetEngine = Nothing
End Sub

Private Sub dbList()
Dim oFolders
Set oFolders = Server.CreateObject("Scripting.FileSystemObject")
Response.Write ("<Select Name=""DBFileName"">")
For Each Item In oFolders.GetFolder(strFolder).Files
If LCase(Right(Item, 4)) = ".mdb" Then
Response.Write ("<Option Value=""" & Replace(Item, strFolder, "") & """>" & Replace(Item, strFolder, "") & "</Option>")
End If
Next
Response.Write ("</Select>")

Set oFolders = Nothing
End Sub


%>
<p><font size="4">压缩并修复数据库：</font></p>
<form method="POST" action="">
<p>数据库名：<%'dbList%><input type="text" value="<%=strDatabase%>" name="DBFileName" readonly> <input type="submit" value="点击压缩并修复数据库" name="cmd"></p>
</form>
<%
' Compact database and tell the user the database is optimized
Select Case Request.form("cmd")
Case "点击压缩并修复数据库"
dbCompact Request.form("DBFileName")
Response.Write (now()&" 成功压缩并修复数据库 " & Request.form("DBFileName") & " 。")
End Select
%>




