Pure coding to achieve Access database establishment or compression!!

Source: Internet
Author: User
Tags access database
Pure coding to achieve Access database establishment or compression!!
<%
' ###### #以下是一个类文件, the following annotation is the method of calling the class ################################################
' # Note: If the system does not support the creation of Scripting.FileSystemObject objects, then the database compression feature will not be available
' # Access Database class
' # Createdbfile Create an Access database file
' # CompactDatabase compressed an Access database file
' # Create object method:
' # Set a = New databasetools
' # by (She) 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, the 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 the error message <br>" & Err.Number & "<br>" & 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

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.