ASP essence source code collection (five-year summary) page 1/20

Source: Internet
Author: User

<%
'####### The following is a class file, the following annotation is the method of calling the class ################################ ################
'# Note: if the system does not support creating a scripting. FileSystemObject object, the database compression function will not be available.
'# Access Database Class
'# Createdbfile: Create an Access database file
'# Compactdatabase compresses an Access database file
'# Object creation method:
'# Set A = new databasetools
'# By (Xiao Hanxue) S. F.
'####################################### ######################################## ##########
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 created. Please check the 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)
'Compressing database files
'0 is Access 97
'1 is 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 be compressed. Please check the 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
Call renamefile (savepath & dbfilename & ". Bak. mdb", savepath & dbfilename)
Set Cd = false
Compactdatabase = true
End if
End Function
Public Function dbexists (byval dbpath)
'Check whether the database file exists
On Error resume next
Dim C
Set c = server. Createobject ("ADODB. Connection ")
C. Open "provider = Microsoft. Jet. oledb.4.0; Data Source =" & dbpath
If err. Number <> 0 then
Err. Clear
Dbexists = false
Else
Dbexists = true
End if
Set c = nothing
End Function
Public Function apppath ()
'Get the current real path
Apppath = server. mappath ("./")
End Function
Public Function appname ()
'Get current Program Name
Appname = mid (request. servervariables ("script_name"), (request. servervariables ("script_name"), "/",-1, 1) + 1, Len (request. servervariables ("script_name ")))
End Function
Public Function deletefile (filespec)
'Delete an object
Dim FSO
Set FSO = Createobject ("scripting. FileSystemObject ")
If err. Number <> 0 then
Response. Write ("An error occurred while deleting the file! View error information
"& Err. Number &"
"& Err. description)
Err. Clear
Deletefile = false
End if
Call FSO. deletefile (filespec)
Set FSO = nothing
Deletefile = true
End Function
Public Function renamefile (filespec1, filespec2)
'Modify an object
Dim FSO
Set FSO = Createobject ("scripting. FileSystemObject ")
If err. Number <> 0 then
Response. Write ("An error occurred while modifying the file name! View error information
"& Err. Number &"
"& Err. description)
Err. Clear
Renamefile = false
End if
Call FSO. copyfile (filespec1, filespec2, true)
Call FSO. deletefile (filespec1)
Set FSO = nothing
Renamefile = true
End Function
End Class
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.