Access database on-line compression implementation:
If you delete data or objects in an Access database, or if you delete an object in an Access project, an Access database or an Access project can cause fragmentation and reduce the efficiency of disk space usage. Compressing an Access database or an Access project actually copies the file and organizes how the file is stored on disk. Compression also optimizes the performance of Access databases and Access projects.
So when we were too slow to tolerate the ASP program that was causing the increasing database, we thought of compressing him. But the usual way to download him to the local and then use MSAccess to complete the compression operation, and then upload! Later I wanted to make it possible to compress the Access database online? I looked up some information for this, but I didn't get it.
I was successful in the local test, and the Internet to their own dynamic network forum implementation of the compression operation results are completely normal, the database from the original 3.7M compressed to 2.1M to prove that it is feasible. Note: This program is actually through the FSO permissions and the Jet engine connection, so before using, please confirm your server support FSO (FileSystemObject) permissions and install the latest driver of access! From a safe start, please back up the original database before compacting! The running environment that has been tested:
WIN98SE+PWS, win2000+iis5.0
below is my collation of the source code, copy saved as Compact.asp and uploaded to the database directory can be used normally.
<html>
<head>
<title>access Database compression program </title>
</head>
<body bgcolor= "E0f8ef" >
<div>
<div align= "center" ><font color= "#3300FF" ><b><font size= "5" > Universal Access Database online compression program </font ></b></font><br>
</div>
<div><br>
This program is actually through the FSO permissions and jet engine connection, so before using, please confirm your server support FSO (FileSystemObject) permissions and install the latest driver of access! From a safe start, please back up the original database before compacting! </div><br>
<div align= "center" > Operating Environment: In WIN98SE+PWS, win2000+iis5.0 <br>
<%
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 = "Your database," & DBPath & ", has been compressed" & VbCrLf
Else
compactdb = "The database path or name you entered is not found, please try again" & VbCrLf
End If
End Function
%>
</div>
</div>
<form name= "compact" method= "POST" action= "compact.asp" >
<div align= "center" ><font size= "2" ><b><font color= "#FF0000" > Compression options, please carefully fill out! </font></b><br>
<br>
Input Database Full name:
<input type= "text" name= "DBPath" >
(including extensions, such as MDB, ASA, ASP, etc.) <br>
<br>
<input type= "checkbox" Name= "boolIs97" value= "True" >
Check for ACCESS97 database <br>
(default is ACCESS2000 database) <br>
<br>
<input type= "Submit" name= "Submit" value= "confirm Compression" >
</font></div>
</form>
<div align= "center" ><font size= "2" >
<%
Dim dbpath,boolis97
DBPath = Request ("DBPath")
boolIs97 = Request ("boolIs97")
If dbpath <> "" Then
DBPath = Server.MapPath (dbpath)
Response.Write (Compactdb (DBPATH,BOOLIS97))
End If
%>
<br>
</font></div>