private void button1_Click(object sender, EventArgs e) { var config = loadConfig(); if (MessageBox.Show(this, $"将为当前指定的数据库服务器{config.DBServer}启用备份加密密钥和证书,启用证书后,备份文件将无法在未使用特定证书的服务器上还原,是否继续?", "数据库配置", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return; } //检查指定目录下有无证书 string certFile = System.IO.Path.Combine(Application.StartupPath, "sql\\AutoBakCert.cer"); string pkFile = System.IO.Path.Combine(Application.StartupPath, "sql\\AutoBakCert.pkey"); if (!System.IO.File.Exists(certFile) || !System.IO.File.Exists(pkFile)) { MessageBox.Show(this, "加密证书不存在!操作失败"); return; } showResult(SQLServerHelper.Exec(string.Format(Resources.AutoBakCert, System.IO.Path.Combine(Application.StartupPath, "sql")), config.DBServer), (sender as Button).Text); //new QDBDog.SqlSugarHelper($"server={tbServer.Text};Initial Catalog=master;Integrated Security=True;Connection Timeout=5;").DoOne(client => //{ // try // { // client.Ado.ExecuteCommand(System.Text.RegularExpressions.Regex.Replace(sqlFile, @"^\s*go\s*\n", "\n", System.Text.RegularExpressions.RegexOptions.Multiline | System.Text.RegularExpressions.RegexOptions.IgnoreCase)); // } // catch (Exception ex) // { // MessageBox.Show(this,ex.Message); // } //}); }
private void button3_Click(object sender, EventArgs e) { var config = loadConfig(); if (MessageBox.Show(this, $"将为当前指定的数据库服务器{config.DBServer}上移除备份加密密钥和证书,移除后,备份文件可以在任意服务器上还原,这可能导致数据泄露,是否继续?", "数据库配置", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return; } showResult(SQLServerHelper.Exec(string.Format(Resources.DropAutoBakCert, Path.Combine(Application.StartupPath, "sql")), config.DBServer), (sender as Button).Text); }
private void button6_Click(object sender, EventArgs e) { try { lockButton(3, sender as Button); var config = loadConfig(false); var a = SQLServerHelper.Exec(@" use master go ALTER SERVER ROLE [sysadmin] ADD MEMBER [NT AUTHORITY\SYSTEM]; print N'提升SYSTEM权限完成' go ", config.DBServer); MessageBox.Show(this, a); } catch (Exception ex) { MessageBox.Show(this, ex.Message); } }