久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

C#:備份和恢復(fù)SQL Server數(shù)據(jù)庫

 唐伯龍 2011-07-02

Backup 對象 定義Microsoft? SQL Server? 的數(shù)據(jù)庫或日志備份操作.

備注

使用 Backup 對象, 你可以:

  • 備份一個 SQL Server 數(shù)據(jù)庫或數(shù)據(jù)庫事務(wù)日志.
  • 產(chǎn)生一個Transact-SQL BACKUP 定義備份的聲明.
  • 監(jiān)聽一個備份操作,,并將狀態(tài)報告給用戶.

For SQL Server, a database delimits the largest backup unit. Though many different database backup images can be maintained on any single medium, a backup cannot span more than a single database. By default, backup operations performed with the Backup object back up a complete database.

SQL Server can write a backup to one of four media types: disk, tape, named pipe, or a proprietary media called a backup device. SQL Server supports backup striping. A striped backup is one directed to more than a single device. When striped, a backup is written across the devices in equal chunks. Striping is supported to a single media type only. That is, a backup can be written to two tape devices. A backup cannot be written half to a tape device and the other half to a disk.

At a minimum, you must supply values for a backup source and a backup target when using the Backup object. The Database property specifies the backup operation source. SQL-DMO implements supported media types in the Backup object properties Files, Devices, Pipes, and Tapes. Use one media type property to specify the backup operation target.

To perform a complete database backup

  1. Create a new Backup object.
  2. Set the Database property, naming the database backed up.
  3. Set a media property to name the target device(s).
  4. Call the SQLBackup method.

In many installations, complete database backup is not a viable option. The Backup object offers access to a number of strategies that ensure data integrity by capturing a subset of the database image.

To back up a database transaction log

  1. Create a new Backup object
  2. Set the Database property, naming the database backed up.
  3. Set the Action property to SQLDMOBackup_Log.
  4. Set a media property to name the target device(s).
  5. Call the SQLBackup method.

To perform a differential backup

  1. Create a new Backup object
  2. Set the Database property, naming the database backed up.
  3. Set the Action property to SQLDMOBackup_Incremental.
  4. Set a media property to name the target device(s).
  5. Call the SQLBackup method.

To back up specific filegroups

  1. Create a new Backup object
  2. Set the Database property, naming the database backed up.
  3. Set the DatabaseFileGroups property, naming the filegroup(s) providing backup source data.
  4. Set a media property to name the target device(s).
  5. Call the SQLBackup method.

To back up specific files

  1. Create a new Backup object
  2. Set the Database property, naming the database backed up.
  3. Set the Action property to SQLDMOBackup_Files.
  4. Set the DatabaseFiles property, naming the file(s) providing backup source data.
  5. Set a media property to name the target device(s).
  6. Call the SQLBackup method.

Settings for any other Backup object properties are optional. Use the optional settings when conditions require extraordinary processing. For example, the MediaName and MediaDescription properties provide, primarily, data used to ensure media availability for tape devices and are applicable when the backup operation defined will initialize the media. For more information about property applicability and use, see individual property documentation.

 

        /// <summary>
        
/// 備份MSSQL SERVER數(shù)據(jù)庫
        
/// </summary>
        
/// <param name="DSN">服務(wù)器名</param>
        
/// <param name="UID">用戶名</param>
        
/// <param name="PWD">密碼</param>
        
/// <param name="DB">數(shù)據(jù)庫名</param>
        
/// <param name="FilePath">備份文件名</param>

        public static void MSSQL_BackupDatabase(string DSN, string UID, string PWD, string DB, string FilePath)
        
{
            SQLDMO.Backup oBackup 
= new SQLDMO.BackupClass();
            SQLDMO.SQLServer oSQLServer 
= new SQLDMO.SQLServerClass();
            
try
            
{
                oSQLServer.LoginSecure 
= false;
                oSQLServer.Connect(DSN, UID, PWD);
                oBackup.Action 
= SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
                oBackup.Database 
= DB;
                oBackup.Files 
= FilePath;
                oBackup.BackupSetName 
= DB;
                oBackup.BackupSetDescription 
= string.Format("{0} 備份", DB);
                oBackup.Initialize 
= true;
                oBackup.SQLBackup(oSQLServer);
            }

            
catch
            
{
                
throw;
            }

            
finally
            
{
                oSQLServer.DisConnect();
            }

        }


        
/// <summary>
        
/// 恢復(fù)MSSQL SERVER數(shù)據(jù)庫
        
/// </summary>
        
/// <param name="DSN">服務(wù)器名</param>
        
/// <param name="UID">用戶名</param>
        
/// <param name="PWD">密碼</param>
        
/// <param name="DB">數(shù)據(jù)庫名</param>
        
/// <param name="FilePath">備份文件名</param>

        public static void MSSQL_RestoreDatabase(string DSN, string UID, string PWD, string DB, string FilePath)
        
{
            SQLDMO.Restore oRestore 
= new SQLDMO.RestoreClass();
            SQLDMO.SQLServer oSQLServer 
= new SQLDMO.SQLServerClass();
            
try
            
{
                oSQLServer.LoginSecure 
= false;
                oSQLServer.Connect(DSN, UID, PWD);
                oRestore.Action 
= SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
                oRestore.Database 
= DB;
                oRestore.Files 
= FilePath;
                oRestore.FileNumber 
= 1;
                oRestore.ReplaceDatabase 
= true;
                oRestore.SQLRestore(oSQLServer);
            }

            
catch
            
{
                
throw;
            }

            
finally
            
{
                oSQLServer.DisConnect();
            }

        }

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,,不代表本站觀點,。請注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購買等信息,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多