コード例 #1
0
        private void BtnBack_Click(object sender, EventArgs e)
        {
            try
            {
                DataBaseConnection.StartConn();

                if (!string.IsNullOrEmpty(BackupPath.Text))
                {
                    SQL = "BACKUP DATABASE Project_DB  TO DISK ='" + BackupPath.Text.Replace("12:00:00 Am", "").Replace("12:00:00 ص", "") + "'";

                    command = new SqlCommand(SQL, DataBaseConnection.Connection());
                    command.ExecuteReader();

                    XtraMessageBox.Show("تم عمل نسخة احتياطية بنجاح  ");
                }
                else
                {
                    XtraMessageBox.Show("يرجى تحديد موقع تخزين النسخة الاحتياطية اولا ");
                }
            }
            catch (Exception E)
            {
                XtraMessageBox.Show(E.Message);
            }
            finally
            {
                command.Dispose();
                DataBaseConnection.CloseConn();
            }
        }
コード例 #2
0
        private void BtnBackupRest_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(BackupResPath.Text))
            {
                try
                {
                    DataBaseConnection.StartConn();


                    string     UseMaster        = "USE master";
                    SqlCommand UseMasterCommand = new SqlCommand(UseMaster, DataBaseConnection.Connection());
                    UseMasterCommand.ExecuteNonQuery();

                    string     Alter1    = @"ALTER DATABASE [Project_DB] SET Single_User WITH Rollback Immediate";
                    SqlCommand Alter1Cmd = new SqlCommand(Alter1, DataBaseConnection.Connection());
                    Alter1Cmd.ExecuteNonQuery();

                    string     Restore    = string.Format("Restore database Project_DB from disk= '" + BackupResPath.Text.ToString() + "' WITH REPLACE");
                    SqlCommand RestoreCmd = new SqlCommand(Restore, DataBaseConnection.Connection());
                    RestoreCmd.ExecuteNonQuery();

                    string     Alter2    = @"ALTER DATABASE [Project_DB] SET Multi_User";
                    SqlCommand Alter2Cmd = new SqlCommand(Alter2, DataBaseConnection.Connection());
                    Alter2Cmd.ExecuteNonQuery();
                }

                catch (Exception)
                {
                    XtraMessageBox.Show("توجد مشكلة اثناء استرجاع قاعدة البيانات");
                }
                finally
                {
                    DataBaseConnection.CloseConn();
                }
            }
            else
            {
                XtraMessageBox.Show("يرجى تحديد مكان الملف قبل محاولة الاسترجاع");
            }
        }