ASP.NET's backup and recovery of the remote SQL Server database

xiaoxiao2021-03-06  39

SQL Server helps document addresses, direct input in IE MK: @MsitStore: c: /program files/microsoft SQL Server/80/Tools/Books/tsqlref.chm :: / ts_ba-bz_35ww.htm

Backup Database to Disk Path Backup Restore Database from Disk Path Restore Using System.collections; Using System.Security.cryptography;

Using system.data; using system.data.sqlclient; using system.Web;

Using system.Web.SessionState; use system.web.ui.webcontrols; using system.Web.ui.htmlControls;

Using system.diagnost; using system.componentmodel; using system.configuration; using system.data.oledb;

Namespace DBService {///

/// DBOPER class, mainly to backup and recovery of Microsoft SQL Server database //// Public Sealed Class Dboper {/// /// DBOPER class Constructor /// // private dboper () // {//}

///

/// database backup /// /// public static string BackFileName = System.Web.HttpContext.Current.Request.PhysicalApplicationPath "BackUp // MyDbBack.bak"; public static void DbBackup (string DbNanme, string userid, string pwd) {try {SQLDMO.Backup oBackup = new SQLDMO.BackupClass (); SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass (); oSQLServer.LoginSecure = false; oSQLServer.Connect ( "localhost" , userid, pwd); oBackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database; oBackup.Database = DbNanme; oBackup.Files = BackFileName; oBackup.BackupSetName = DbNanme; oBackup.BackupSetDescription = "database backup"; oBackup.Initialize = true; oBackup . Sqlbackup (OSQLServer);} catch {throw;}}

///

/// restore database function /// /// Database name /// database backup file the full pathname /// public bool RestoreDB (string strDbName, string strFileName, string userid, string pwd) {// PBar = pgbMain; SQLDMO.SQLServer svr = new SQLDMO.SQLServerClass (); Try {// server name, database username, database username password Svr.connect ("localhost", userid, pwd); sqldmo.queryresults = svr.enumprocesses (-1); int icolpidnum = -1; INT iCOLDBNAME = -1; for (int i = 1; i

}

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

New Post(0)