In depth analysis of ASP online compression method of access database

  • 2021-11-24 01:15:16
  • OfStack

ASP online compression ACCESS database principle is very simple: JRO. JetEngine compression function to establish a new database file, and then the original delete, replace! In this case, the compressor only needs a few lines to ok!

Save the following code as **. asp, database files (db. md) in the same directory, asp done!


<%
oldDB = server.mappath("db.mdb") ' Change database address 
newDB = server.mappath("db_new.mdb") ' Generate temporary files 
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set Engine = Server.CreateObject("JRO.JetEngine")
prov = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
Engine.CompactDatabase prov & OldDB, prov & newDB
set Engine = nothing
FSO.DeleteFile oldDB ' Delete temporary files 
FSO.MoveFile newDB, oldDB
set FSO = Nothing
response.write "OK"
%>

The following is a encapsulation function for ASP to compress ACCESS database online


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")
On Error Resume Next
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
 
If Err Then
response.write "<script LANGUAGE='javascript'>alert(' Unrecognized database type .');history.go(-1);</script>"
response.end
end if
fso.CopyFile strDBPath & "temp.mdb",dbpath
fso.DeleteFile(strDBPath & "temp.mdb")
Set fso = nothing
Set Engine = nothing
CompactDB = "<script>alert(' Compression succeeded! ');javascript:history.go(-1);</script>"
Else
CompactDB = "<script>alert(' Database not found! \n Please check whether the database path is entered incorrectly! ');history.back();</script>"
End If
End Function 

Summarize


Related articles: