コード例 #1
0
ファイル: BakHelper.cs プロジェクト: abc52406/DomainCheck
        /// <summary>
        /// 还原数据库
        /// </summary>
        /// <param name="serverName">数据实例名</param>
        /// <param name="userName">用户</param>
        /// <param name="password">密码</param>
        /// <param name="databaseName">库名</param>
        /// <param name="path">文件路径</param>
        public static void RestoreDatabase(string serverName, string userName, string password, string databaseName, string path)
        {
            SQLDMO.Restore oRestore   = new SQLDMO.Restore();
            SQLServer      oSQLServer = new SQLServer();

            try
            {
                oSQLServer.LoginSecure = false;
                oSQLServer.Connect(serverName, userName, password);
                oRestore.Action          = SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
                oRestore.Database        = databaseName;
                oRestore.Files           = path;
                oRestore.FileNumber      = path.Split(',').Count();
                oRestore.BackupSetName   = databaseName;
                oRestore.ReplaceDatabase = true;
                oRestore.SQLRestore(oSQLServer);
            }
            catch
            {
                throw;
            }
            finally
            {
                oSQLServer.DisConnect();
            }
        }
コード例 #2
0
ファイル: BakHelper.cs プロジェクト: abc52406/PbTool
 /// <summary>
 /// 还原数据库
 /// </summary>
 /// <param name="serverName">数据实例名</param>
 /// <param name="userName">用户</param>
 /// <param name="password">密码</param>
 /// <param name="databaseName">库名</param>
 /// <param name="path">文件路径</param>
 public static void RestoreDatabase(string serverName, string userName, string password, string databaseName, string path)
 {
     SQLDMO.Restore oRestore = new SQLDMO.Restore();
     SQLServer oSQLServer = new SQLServer();
     try
     {
         oSQLServer.LoginSecure = false;
         oSQLServer.Connect(serverName, userName, password);
         oRestore.Action = SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
         oRestore.Database = databaseName;
         oRestore.Files = path;
         oRestore.FileNumber = path.Split(',').Count();
         oRestore.BackupSetName = databaseName;
         oRestore.ReplaceDatabase = true;
         oRestore.SQLRestore(oSQLServer);
     }
     catch
     {
         throw;
     }
     finally
     {
         oSQLServer.DisConnect();
     }
 }