Online Build Library

Source: Internet
Author: User
Tags exit
Online <%
On Error Resume Next
Class Createdb
'
'
' Create a database
Usage
' Dim cdb
' Set Cdb=new createdb
' Cdb.setdbname= database name
' If Cdb.ifok then Response.End database already exists
' Cdb.run
' Check to see if it is running successfully
' If Cdb.ifok then
' Response.Write Cdb.errs
' End If

Private dbname ' database name
Private Ifsure ' is used to save the flag of success, if the success value is false, the failure is true, the initial value is True
Private Errstr ' Save the text that explains the error

' Get ifsure value
Property Get Ifok ()
Ifok=ifsure
End Property

' Get Errstr value
Property Get Errs ()
Errs=errstr
End Property

'
Private Sub Class_Initialize ()
' Set the initial value of the IFSURE,ERRSTR
Ifsure=true
errstr= "Online Build Library"
End Sub

' Set database name
Property Let Setdbname (ByVal dbn)

Dbname=dbn
' Check if the database already exists
Ifexistdb DBN

End Property

Public Sub Run ()

'
Class_Initialize
' Check to see if the database name is empty
If IsNull (dbname) or IsEmpty (dbname) or CStr (dbname) = "" Then
Errstr= "Failed to establish database, database name cannot be empty"
Ifsure=true
Exit Sub
End If

' This sentence cannot be placed in the IFEXISTDB, nor can it be executed later, because the database automatically exits this class when it is not found.
' may be too serious a mistake, so you can only clean up the wrong code in another place.
Err.Clear

Dim objcreate ' Save Adox.catalog Object

Set Objcreate=server.createobject ("Adox.catalog")
If Err.number<>0 Then
Errstr= failed to establish Adox.catalog object, please check your user permissions. "+err.description
Set objcreate=nothing
Ifsure=true
Exit Sub
End If

' Build a Database
Objcreate.create ("Data source=" +server.mappath (dbname) + ";p rovider=microsoft.jet.oledb.4.0")
If Err.number<>0 Then
Errstr= failed to build the database. <br> "+err.description
Ifsure=true
Set objcreate=nothing
Exit Sub
End If
' If there is no error, set the success flag
Ifsure=false

End Sub



Private Sub Ifexistdb (ByVal dbn)
' Restore class state
Ifsure=false
' If the database exists, set to true, because if it does not exist, you cannot continue to execute this class
' Check if the database already exists
Dim conn
Set Conn=server.createobject ("Adodb.connection")
conn.connectionstring= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" +server.mappath (DBN)
Conn.Open
If Err.number=0 Then
Errstr= "Database already exists"
Ifsure=true
Conn.close
Set conn=nothing
End If


End Sub

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.