Пример #1
0
        public static async Task <bool> VerifyBackup(SqlInstance instance, string filename, CancellationToken token)
        {
            var sb = new StringBuilder("RESTORE VERIFYONLY FROM DISK='@filename'");

            sb.Replace("@filename", filename);

            var verify = Task.Run(() => instance.ExecuteNonQueryAsync(sb.ToString(), token));

            await verify;

            if (token.IsCancellationRequested)
            {
                throw new OperationCanceledException();
            }
            return(verify.Result);
        }
Пример #2
0
        private async void btnCreate_Click(object sender, EventArgs e)
        {
            var dbname = txtName.Text;

            if (!Utils.IsStringValid(dbname))
            {
                lblStatus.ForeColor = Color.Red;
                lblStatus.Text      = dbname + " is not a valid name.";
                txtName.Focus();
                return;
            }
            if (_instance.DatabasesCollection.FirstOrDefault(s => s.Name == dbname) != null)
            {
                lblStatus.ForeColor = Color.Red;
                lblStatus.Text      = dbname + " exists yet.";
                txtName.Focus();
                return;
            }
            btnCreate.Enabled = false;

            var sbCreate = new StringBuilder("CREATE DATABASE [@dbname];");

            sbCreate.Append("ALTER DATABASE [@dbname] SET RECOVERY @recovery;");

            if (ckbCreate.GetItemChecked(0))
            {
                sbCreate.Append("ALTER DATABASE [@dbname] SET AUTO_CLOSE ON;");
            }
            else if (!ckbCreate.GetItemChecked(0))
            {
                sbCreate.Append("ALTER DATABASE [@dbname] SET AUTO_CLOSE OFF;");
            }
            if (ckbCreate.GetItemChecked(1))
            {
                sbCreate.Append("ALTER DATABASE [@dbname] SET AUTO_CREATE_STATISTICS ON;");
            }
            else if (!ckbCreate.GetItemChecked(1))
            {
                sbCreate.Append("ALTER DATABASE [@dbname] SET AUTO_CREATE_STATISTICS OFF;");
            }
            if (ckbCreate.GetItemChecked(2))
            {
                sbCreate.Append("ALTER DATABASE [@dbname] SET AUTO_UPDATE_STATISTICS ON;");
            }
            else if (!ckbCreate.GetItemChecked(2))
            {
                sbCreate.Append("ALTER DATABASE [@dbname] SET AUTO_UPDATE_STATISTICS OFF;");
            }
            if (ckbCreate.GetItemChecked(3))
            {
                sbCreate.Append("ALTER DATABASE [@dbname] SET AUTO_UPDATE_STATISTICS_ASYNC ON;");
            }
            else if (!ckbCreate.GetItemChecked(3))
            {
                sbCreate.Append("ALTER DATABASE [@dbname] SET AUTO_UPDATE_STATISTICS_ASYNC OFF;");
            }
            if (ckbCreate.GetItemChecked(4))
            {
                sbCreate.Append("ALTER DATABASE [@dbname] SET AUTO_SHRINK ON;");
            }
            else if (!ckbCreate.GetItemChecked(4))
            {
                sbCreate.Append("ALTER DATABASE [@dbname] SET AUTO_SHRINK OFF;");
            }
            if (ckbCreate.GetItemChecked(5))
            {
                sbCreate.Append("ALTER DATABASE [@dbname] SET ENABLE_BROKER;");
            }
            else if (!ckbCreate.GetItemChecked(5))
            {
                sbCreate.Append("ALTER DATABASE [@dbname] SET DISABLE_BROKER;");
            }

            sbCreate.Replace("@dbname", txtName.Text);
            sbCreate.Replace("@recovery", cmbRecovery.SelectedItem.ToString());

            var result = Task.Run(() => _instance.ExecuteNonQueryAsync(sbCreate.ToString()));

            try
            {
                await result;
                Utils.WriteLog("result is::: " + result.Result);
                if (result.Result)
                {
                    lblStatus.ForeColor = Color.Green;
                    lblStatus.Text      = dbname + " created!";
                    var oDatabase = new SqlDatabase(_instance, dbname, "ONLINE", 0);
                    _instance.DatabasesCollection.Add(oDatabase);
                }
            }
            catch (Exception)
            {
                lblStatus.ForeColor = Color.Red;
                lblStatus.Text      = string.Format("{0} not created, check the log.", txtName.Text);
                txtName.Focus();
                return;
            }
            btnCreate.Enabled = true;
        }
Пример #3
0
        public static async Task<bool> VerifyBackup(SqlInstance instance, string filename, CancellationToken token)
        {
            var sb = new StringBuilder("RESTORE VERIFYONLY FROM DISK='@filename'");
            sb.Replace("@filename", filename);

            var verify = Task.Run(() => instance.ExecuteNonQueryAsync(sb.ToString(), token));

            await verify;
            if (token.IsCancellationRequested)
            {
                throw new OperationCanceledException();
            }
            return verify.Result;
        }