(Original) Backup Database Class ACCESS

xiaoxiao2021-03-06  112

Because for this reason, it is sometimes necessary to back up the database, such as backup of the SQL database, but the backup of the SQL database is sometimes a bit troubles, it is not easy to get on the page, so this is very simple, set up a backup file The address and data source are directly transfer. Class usage methods are described in detail below.

There are also some benefits that you can save each different table to different files, and don't redefine the class, the method is to change a different target file before the Transfer table, such as: objclass.targetfile = tfilesult = Objclass .Transfer ("Number", "Number", "" ") Objclass.targetfile = Server.mappath (". ") &" / New.mdb "SResult = Objclass.transfer (" test "," test ", "", "") <% Class transferDatabaseclass' / ************************************************ ********************************************** The / * Transfer Data Class (Backup Database Class) '/ * author: dead in the water fish (dead) '/ * date: August 3, 2004' /*Blog:http://blog.9cbs.com/bpfish'/*'/* usage: '/ * Method 1: (Access database file to access database file) '/ * 1, first set the source database file Sourcefile (optional) and target database file TargetFile (required)' / * 2, use Transfer ("Source Form" , "Target Table Name", "Field List", Transfer Conditions) Method Transfer Data '/ * Example:' / * Dim Sfile, TFile, ObjClass, SResult '/ * sfile = Server.mAppath ("Data / Data. MDB ") '/ * tfile = server.mappath (". ") &" / back.mdb "/ * set objclass = new transfertatabaseclass' / * objclass.sourcefile = sfile '/ * objclass.targetfile = tfile' / * SResult = Objclass.Transfer ("Table1", "NewTable", "" ") '/ * if SResult the' / * response.write" Transfer Data Success! "'/ * else' / * response.write" Transfer Data failed! "'/ * End if' / * set Objclass = Nothing '/ *' / * Method 2: (Other Database Files To Access Database File) '/ * 1, set the target database file TargetFile' / * 2, set the adodb.connection object '/ * 3, then use Transfer "Source Name", "Target Table Name", Field List, "Transfer Condition") Method Transfer Data '/ * Example: (Use Access Data Source Example, you can use other data sources)'

/ * DIM CONN, CONNSTR, TFILE, OBJCLASS, SRESULT '/ * TFILE = Server.mappath (".") & "/ Back.mdb" / * set conn = server.createObject ("adoDb.connection")' / * Connstr = "provider = microsoft.jet.Oledb.4.0; data source =" & Server.mappath ("data / data.mdb") '/ * conn.open connStr' / * set objclass = new transfertatabaseclass' / * set Objclass.conn = conn 'The key' / * objclass.targetfile = tfile '/ * SResult = Objclass.Transfer ("Table1", "NewTable", "" ")' / * if SResult Then '/ * response .Write "transfer data success!" '/ * Else' / * response.write "Transfer data failed!" '/ * End if' / * set objclass = Nothing '/ * conn.close' / * set conn = Nothing ' / * '/ * Description: TargetFile property must be set! (Backup file address, absolute address!) '/ * If you do not set SourceFile, you must set up CONN, which must be one of these two properties, but the priority is a conn' / * method: Transfer ("Source Data Name", "Target Data Table Name", "Field List", "Transfer Condition") '/ * "Source Data Table" Be sure to exist in data sources, "Target Data Table" does not exist in the target file' / * "field list; Transfer Condition "Format" Field List "," Query Condition "format The same '/ *" field list "is all fields," Query Condition "is empty, get all data' / ****** *********************************************************** ******************************************************************************************************************** *********************************************************** '/ * Global Variable' / * External Direct Use: [Obj]. SourceFile = Source File Name [OBJ] .targetFile = Target File Name '/ ***************** *********************************************************** ******* Public SourceFile, TargetFilePrivate Sub Class_initialize S_Conn =

NullEnd SubPrivate Sub Class_Terminate If IsObject (s_Conn) And Not IsNull (s_Conn) Then s_Conn.Close Set s_Conn = Nothing End If If IsObject (Adox) Then Set Adox = Nothing End IfEnd Sub '/ ********** *********************************************************** *************** '/ * Settings / Return Conn Object' / * Description: Add this is set for data transfer to other databases (such as: MSSQL) to the Access database. *********************************************************** ********************************** PUBLIC PROPERTY SET CONN (SNEWVALUE) IF Not IsObject (SNewValue) THEN S_CONN = NULL ELSE SET S_CONN = SNEWVALUE END IFEND PropertyPublic Property GET CONN IF ISOBJECT (S_CONN) THEN SET CONN = S_CONN ELSE S_CONN = NULL END IFEND Property '/ *********************************************** ***************************************************************** / * Data Transfer '/ * Function: Transfer Source Data to TargetFile Database File' / * Function Description: Transfer '/ * Function Returns Using SQL Statements: Return to Some State Code True = Transfer Data Success False = Transfer Data Failure '/ * Function parameters : Stablename = Name of the source database TTABLENAME = Target Database (Automatically created, if there is an error) '/ * scol = To transfer the field list of data, the format is the same in the field list format of SELECT' / * ssql = The condition when transferring data is the same as the WHERE of the SQL statement, '/ ********************************************************* **************************************** PUBLIC FUNCTION TRANSFER (Stablename, Ttablename, Scol , SSQL) On Error Resume Nextdim SQL if not initconn dam, if the conn object is not initialized Transfer = false exit function end if if not createmdbfile kiln, establishing backup Access database file error, transfer data error =

FALSE EXIT FUNCTION End if IF SSQL <> "" The '"" "& SSQL End if IF =" "" field list, "," SCOL = "*" end if SQL = "SELECT" & scol & "INTO [" & Ttablename & "] IN '" & TargetFile & "" & "" & stablename "& ssql s_conn.execute sql if err.Number <> 0 THEN' error Transfer data error, otherwise transfer data success Err.clear transfert = false else transfer = true end ifend function '/ ****************************************************** ************************************************** / * establish an Access Database file '/ * Function function: Establish this file '/ * function description according to the value of TargetFile: Establish a database file' / * function with the CREATE method of the AdoX component Return: Return to some status code '/ ************ *********************************************************** ****************** * ON ERROR RESUMEMDBFILE () ON ERROR RESUME MDBFILE = FALSE 'Error EXIT FUNT IF IF NOT INTOX TEN' Initialization Adox object, establish MDB file Createmdbfile = false 'initialization Adox Error EXIT function end if adox.create "provider = microsoft.jet.Oledb.4.0; data source =" & targetfile if err.number <> 0 TEN' Establishing MDB file error if err.number = -2147217897 Then createmdbfile = true 'file already exists, so established successfully else createmdbfile = false'

Other reasons End if err.clear exit function end if createmdbfile = true 'Establishing MDB file success End function' / *********************************** *********************************************************** / * Initialization Adox.catalog component object '/ *' / *********************************************** ********************************************************************************************************* Private function initox () on Error ResMe Next if not isobject (Adox) Or IsNull (Adox) Then Set Adox = Server.CreateObject ( "ADOX.Catalog") if Err.Number <> 0 Then InitAdox = False Err.Clear Adox = Null Exit Function End If End If InitAdox = TrueEnd Function ' / ************************************************** ************************** / * Initialize AdoDb.Connection Component Object '/ *' / ********* *********************************************************** *********************** Private function initconn () ON Error ResMe nextddim Connstr If Not IsObject (s_Conn) Or IsNull (s_Conn) Then If SourceFile = "" Then InitConn = False Exit Function Else Set s_Conn = Server.CreateObject ( "ADODB.Connection") ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = "& Sourcefile S_Conn.open Connstr if Err.Number <> 0 Then INITCONN = false err.clear s_conn =

转载请注明原文地址:https://www.9cbs.com/read-125600.html

New Post(0)