예제 #1
0
        public void RestoreDb(string fileName, string filePath)
        {
            string          sqlRestore = "Use master Restore Database [" + fileName + "] from DISK='" + filePath + "'";
            string          drop       = "drop database " + fileName;
            ClsConnectLocal cnn        = new ClsConnectLocal();

            cnn.ClsConnect();
            cnn.UpdateDataText(drop);
            cnn.UpdateDataText(sqlRestore);
            cnn.DongKetNoi();
        }
예제 #2
0
        public void BackupDatabase(string BackUpLocation, string BackUpFileName, string DatabaseName)
        {
            string SQLBackUp = "";

            DatabaseName = "[" + DatabaseName + "]";
            string fileUNQ = DateTime.Now.Day.ToString() + "_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year.ToString() + "_" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + "_" + DateTime.Now.Second.ToString();

            //BackUpFileName = BackUpFileName + fileUNQ + ".bak";
            if (Option1.IsChecked == true)
            {
                SQLBackUp = @"BACKUP DATABASE " + DatabaseName + " TO DISK = N'" + BackUpLocation + @"\" + BackUpFileName + @"'";
            }
            else
            {
                SQLBackUp = @"RESTORE DATABASE " + DatabaseName + " FROM DISK = N'" + BackUpLocation + @"'";
                //restore database testdb1 from disk='c:\testdb1.bak'
            }
            MessageBox.Show(SQLBackUp);
            try
            {
                cls.ClsConnect();
                lblMess.Content = "Đang restore ....";
                string alter = "alter database " + DatabaseName + "set single_user with rollback immediate";
                cls.UpdateDataText(alter);
                string drop = "drop database " + DatabaseName;
                cls.UpdateDataText(drop);
                cls.UpdateDataText(alter);
                cls.UpdateDataText(SQLBackUp);
                lblMess.Content = "Done";
                //string mess = SQLBackUp + " ######## Server name  Database " + DatabaseName + " successfully backed up to " + BackUpLocation + @"\" + BackUpFileName + "\n Back Up Date : " + DateTime.Now.ToString();
                string mess = "Backup " + DatabaseName + " successfully backed up to " + BackUpLocation + @"\" + BackUpFileName;
                MessageBox.Show(mess, "Successfully backed", MessageBoxButton.OK, MessageBoxImage.Information);
            }

            catch (Exception ex)
            {
                //lblResult.Content = ex.ToString();
                //lblPath.Content = SQLBackUp + " ######## Server name  Database " + DatabaseName + " successfully backed up to " + BackUpLocation + @"\" + BackUpFileName + "\n Back Up Date : " + DateTime.Now.ToString();
                MessageBox.Show(ex.Message);
            }

            finally
            {
                cls.DongKetNoi();
            }
        }
예제 #3
0
        //end

        //----------------------------------------------------------------
        public void BackUpDb(string fileName, string filePath)
        {
            string          sqlBackup = "BACKUP DATABASE [" + fileName + "] TO DISK='" + filePath + "'";
            ClsConnectLocal cnn       = new ClsConnectLocal();

            cnn.ClsConnect();
            cnn.UpdateDataText(sqlBackup);
            cnn.DongKetNoi();
        }