Database: SQL Server; Reference SQLDMO ◆ Data Backup: /// /// Backup Database /// Summary> Private Void BtnBackup_Click (Object Sender, System.EventArgs E) {this.cursor = Cursors.Waitcursor; This.Label1.Text = "The data backup of the archive library can take a few seconds to dozens of time, please wait ..."; this.label1.visible = true; this.label1.refresh (); THIS.PBAR1.Visible = true; // ---------------------------------------- ------------------------------------------ String SelfName = "D: / NorthwindBak "; string deviceName =" NorthwindBak "; string remark =" backup test "; // ◆ data backup: SQLDMO.Backup oBackup = new SQLDMO.BackupClass (); SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass (); oBackup .Action = 0; oBackup.Initialize = true; SQLDMO.BackupSink_PercentCompleteEventHandler pceh = new SQLDMO.BackupSink_PercentCompleteEventHandler (Step); oBackup.PercentComplete = pceh; try {oSQLServer.LoginSecure = false; oSQLServer.Connect (Common.MySettings.SqlServerName, " sa "," "); OBACKUP.Action = SQLDMO.SQLDMO_BACKU P_TYPE.SQLDMOBackup_Database; oBackup.Database = "Northwind"; // database name oBackup.Files = selfName; // file path oBackup.BackupSetName = deviceName; // backup name oBackup.BackupSetDescription = remark; // Backup description oBackup.Initialize = True; Obackup.sqlbackup (osqlserver);} catch (system.exception ex) {common.showmsg ("Data Backup Failure: / N" EX.TOSTRING ());} finally {osqlser.disconnect ();} // -------------------------------------------------- ---------------------------------- this.Label1.visible = false; this.pbar1.visible =
False; this.cursor = cursors.default;} /// /// Display backup progress bar /// summary> private void step (string message, int init percent) {this.pbar1.value = percent; } ◆ Data restore: /// /// Restore database /// summary> private void btnrestore_click (object sender, system.eventargs e) {this.cursor = Cursors.waitcursor; this.label1.text = "The data restore of the archive library, this may take a few seconds to dozens of time, please wait ..."; this.label1.visible = true; this.label1.refresh (); this.pbar1.visible = True; // -------------------------------------------------------------------------------------------- -------------------------------------- String filename = "northwindbak"; string filepath = "D : / NorthwindBak "; string remark =" backup test "; SQLDMO.Restore oRestore = new SQLDMO.RestoreClass (); SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass (); oRestore.Action = 0; SQLDMO.RestoreSink_PercentCompleteEventHandler pceh = new SQLDMO .RESTORESINK_PERCENTCOMPLETEEVENTHANDLER (STEP); orestore.percentcomplete = PCEH; Try {OSQLServer.con NECT (Common.MySettings.SqlServerName, "SA", "); SqldMo.QueryResults = osqlserver.enumprocesses (-1); int iclpidnum = -1; int icholdbname = -1; // kill other connection process for (INT i = 1; i <= qr.columns; i ) {string strname = qr.get_columnname (i); if (Strname.toupper (). Trim () == "SPID") {iclpidnum = i;} Else IF (Strname.toupper (). Trim () =
= "DBNAME") {iColdBName = i;} if (iColpidNum! = -1 && icholdbName! = -1) Break;} for (INT i = 1; i <= qr.rows; i ) {int LPID = QR. GetColumnLong (i, iColPIDNum); string strDBName = qr.GetColumnString (i, iColDbName); if (strDBName.ToUpper () == "CgRecord" .ToUpper ()) oSQLServer.KillProcess (lPID);} oRestore.Action = SQLDMO. SQLDMO_RESTORE_TYPE.SQLDMORestore_Database; oRestore.Database = "Northwind"; oRestore.Files = filePath; oRestore.FileNumber = 1; oRestore.ReplaceDatabase = true; oRestore.SQLRestore (oSQLServer);} catch (System.Exception ex) {Common.ShowMsg ( "Data Restore Failure: / N" EX.TOString ());} Finally {OSQLServer.disconnect ();} // --------------------- -------------------------------------------------- ------------- this.label1.visible = false; this.pbar1.visible = false; this.cursor = cursors.default;} /// /// Display reduction progress条 /// summary> private void step (string message, int init) {this.pbar1.value = percent;