Exemplo n.º 1
0
        /// <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();
            }
        }
Exemplo n.º 2
0
 /// <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();
     }
 }