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
%>