<%
'######The following is a class file, and the following annotation is the method of calling the class###################################################################################################################################################################################################################################
'# Note: If the system does not support the creation of Scripting.FileSystemObject object, the database compression function will not be used.
'# Access database class
'# CreateDbFile Creates an Access database file
'# CompactDatabase Compresses an Access database file
'# Create object method:
'# Set a = New DatabaseTools
'# by (Xiao Hanxue) sf
'#########################################################################################
Class DatabaseTools
Public function CreateDBfile(byVal dbFileName, byVal DbVer, byVal SavePath)
'Create a database file
'If DbVer is 0 Then Create Access97 dbFile
'If DbVer is 1 Then Create Access2000 dbFile
On error resume Next
If Right(SavePath,1)<>"/" Or Right(SavePath,1)<>"/" Then SavePath = Trim(SavePath) & "/"
If Left(dbFileName,1)="/" Or Left(dbFileName,1)="/" Then dbFileName = Trim(Mid(dbFileName,2,Len(dbFileName)))
If DbExists(SavePath & dbFileName) Then
Response.Write ("Sorry, this database already exists!")
CreateDBfile = False
Else
Dim Ca
Set Ca = Server.CreateObject("ADOX.Catalog")
If Err.number<>0 Then
Response.Write ("Cannot be established, please check for error message
" & Err.number & "
" & Err.Description)
Err.Clear
Exit function
End If
If DbVer=0 Then
call Ca.Create("Provider=Microsoft.Jet.OLEDB.3.51;Data Source=" & SavePath & dbFileName)
Else
call Ca.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & SavePath & dbFileName)
End If
Set Ca = Nothing
CreateDBfile = True
End If
End function
Public function CompactDatabase(byVal dbFileName, byVal DbVer, byVal SavePath)
'Compress database files
'0 for access 97
'1 for access 2000
On Error resume next
If Right(SavePath,1)<>"/" Or Right(SavePath,1)<>"/" Then SavePath = Trim(SavePath) & "/"
If Left(dbFileName,1)="/" Or Left(dbFileName,1)="/" Then dbFileName = Trim(Mid(dbFileName,2,Len(dbFileName)))
If DbExists(SavePath & dbFileName) Then
Response.Write ("Sorry, this database already exists!")
CompactDatabase = False
Else
Dim Cd
Set Cd = Server.CreateObject("JRO.JetEngine")
If Err.number<>0 Then
Response.Write ("Cannot compress, please check for error message
" & Err.number & "
" & Err.Description)
Err.Clear
Exit function
End If
If DbVer=0 Then
call Cd.CompactDatabase("Provider=Microsoft.Jet.OLEDB.3.51;Data Source=" & SavePath & dbFileName,"Provider=Microsoft.Jet.OLEDB.3.51;Data
Source=" & SavePath & dbFileName & ".bak.mdb;Jet OLEDB;Encrypt Database=True")
Else
call Cd.CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
SavePath & dbFileName,"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
SavePath & dbFileName & ".bak.mdb;Jet OLEDB;Encrypt Database=True")
End If
'Delete old database files
call DeleteFile(SavePath & dbFileName)
'Restore the compressed database file