server| Backup | recovery | data | database SQLDMO(SQL distributed Management objects,sql Distributed Management Objects) encapsulates objects in a Microsoft SQL Server database. SQLDMO is the application interface used by Enterprise Manager in Microsoft SQL Server, so it can perform many functions, including, of course, backup and recovery of the database.
SQLDMO is brought by Microsoft SQL Server SQLDMO.dllProvided, as SQLDMO.dllis a COMObjects (about COMThe concept of, please refer to my com and COM + technologyThat article), so everyone must be in before using. NET project, add a reference to it.
The following is a class written in the C # language for backup and recovery of Microsoft SQL Server databases:
public sealed class dboper { ///<summary> // /Dboper class constructor///author:shadow ///</summary> private DbOper () { } ///<summary> ///Database backup ///</summary> public static void DbBackup () { SQLDMO. Backup obackup = new SQLDMO. Backupclass (); SQLDMO. SQL Server oSQLServer = new SQLDMO. Sqlserverclass (); try { osqlserver.loginsecure = false; osqLserver.connect ("localhost", "sa", "1234"); obackup.action = SQLDMO. Sqldmo_backup_type. Sqldmobackup_database; obackup.database = "Northwind"; obackup.files = @ "D:\Northwind.bak"; obackup.backupsetname = "Northwind"; obackup.backupsetdescription = "Database Backup"; obackup.initialize = true; obackup.sqlbackup (oSQLServer); } catch { throw; } finally { Osqlserver.disconnect (); } } /// <summary> ///Database Recovery ///</summary> public static void Dbrestore () { SQLDMO. Restore Orestore = new SQLDMO. Restoreclass (); SQLDMO. SQL Server oSQLServer = new SQLDMO. Sqlserverclass (); try { &NBSP;&Nbsp; osqlserver.loginsecure = false; osqlserver.connect ("localhost", "sa", " 1234 "); orestore.action = SQLDMO. Sqldmo_restore_type. Sqldmorestore_database; orestore.database = "Northwind"; orestore.files = @ "D:\Northwind.bak"; orestore.filenumber = 1; orestore.replacedatabase = true; Orestore.sqlrestore (oSQLServer); } catch { throw; } finally { Osqlserver.disconnect (); } }}