none
problem with smo

    Pregunta

  • hi all

    i want restore my backup with this code but then i use it then dont affect anything.

    i dont get any error and it do nothing.

    public void RestoreDatabase()
            {
                string sConnect = Properties.Settings.Default.VideoArchiveDBConnectionString;
                string dbName;
                
                using (SqlConnection cnn = new SqlConnection(sConnect))
                {
                    try
                    {
                        cnn.Open();
                        dbName = cnn.Database.ToString();
    
                        ServerConnection sc = new ServerConnection(cnn);
                        Server sv = new Server(sc);
                        // Check that I'm connected to the user instance
    
                        OpenFileDialog openFile = new OpenFileDialog();
                        //openFile.ShowDialog();
                        // Create backup device item for the backup
                        BackupDeviceItem bdi = new BackupDeviceItem(@"C:\Backup.bak", DeviceType.File);
    
                    
                        /*SqlCommand com = new SqlCommand();
                        string UseMaster = "USE master";
                        string restore = "RESTORE DATABASE Battalion FROM DISK ='c:\\Backup.bak' WITH FILE = 1 , REPLACE";
                        string Alter1 = @"ALTER DATABASE [" + dbName + "] SET Single_User WITH Rollback Immediate";
                        string Alter2 = @"ALTER DATABASE [" + dbName + "] SET Multi_User";
                        // sv.Databases[dbName].Drop();
                        cnn.ChangeDatabase("Master");
                        com.Connection = cnn;
                        com.CommandText = UseMaster;
                        com.ExecuteNonQuery();
                        com.CommandText = Alter1;
                        com.ExecuteNonQuery();
                        com.CommandText = restore;
                        com.ExecuteNonQuery();*/
                        // Create the backup informaton
                        Backup bk = new Backup();
                        Restore res = new Restore();
    
                        res.Devices.AddDevice(@"C:\Backup.bak", DeviceType.File);
                        res.Database = "VideoArchiveDB";
                        res.Action = RestoreActionType.Database;
                        res.ReplaceDatabase = true;
                        res.NoRecovery = false;
                        res.ClearSuspectPageTableAfterRestore = true;
                        res.SqlRestore(sv); 
                        SqlConnection.ClearAllPools();
                    }
                    catch (Exception ex)
                    {
                        
                    }
                } 
    

    can anyone help me?

    thankful.

    miércoles, 11 de enero de 2012 4:25

Todas las respuestas