请高手解答
---------------------------------------------------------------
While working on BuildDB/Buildapp online Demo, I developed a little function that will compact Access databases over the web. Here's a "no-frills" page that'll compact the databases for you.
One problem with Access databases is that "holes" are created when records are deleted, making the database fluffy and bloated. Compacting the database makes it lean and efficient again.
Note: This function/page can easily be combined with the Buildapp front end file navigation and search pages (Installment II), to create an application that'll make it easy to handle this formerly troublesome chore for all the databases on your machine/web site..
++++++++++++ Begin Compact.asp +++++++++++++++++++++++++++++
1
2option explicit
3Const JET_3X = 4
4
5Function CompactDB(dbPath, boolIs97)
6Dim fso, Engine, strDBPath
7strDBPath = left(dbPath,instrrev(DBPath,"\"))
8Set fso = CreateObject("Scripting.FileSystemObject")
9
10If fso.FileExists(dbPath) Then
11Set Engine = CreateObject("JRO.JetEngine")
12
13If boolIs97 = "True" Then
14Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath, _
15"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb;" _
16& "Jet OLEDB:Engine Type=" & JET_3X
17Else
18Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath, _
19"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb"
20End If
21fso.CopyFile strDBPath & "temp.mdb",dbpath
22fso.DeleteFile(strDBPath & "temp.mdb")
23Set fso = nothing
24Set Engine = nothing
25CompactDB = "Your database, " & dbpath & ", has been Compacted" & vbCrLf
26Else
27CompactDB = "The database name or path has not been found. Try Again" & vbCrLf
28End If
29
30End Function
1<html><head><title>Compact Database</title></head><body>
2<h2 align="center"> Compacting an Access database</h2>
3<p align="center">
4<form action="compact.asp">
5Enter relative path to the database, including database name.<br/><br/>
6<input name="dbpath" type="text"/><br/><br/>
7<input name="boolIs97" type="checkbox" value="True"/> Check if Access 97 database
8<br/><i> (default is Access 2000)</i><br/><br/>
9<input type="submit"/>
10<form>
11<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
1</form></form></p></body></html>
++++++++++++ End Code