using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace Email_Client { public partial class Backup : Form { private SqlCommand cmd; string sql = ""; public Backup() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=email_client;Integrated Security=True"); con.Open(); try { SqlCommand cmd = new SqlCommand("backup database email_client to disk ='" + textBox1.Text + "\\" + textBox2.Text + ".bak'", con); cmd.ExecuteNonQuery(); MessageBox.Show("done"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void button1_Click(object sender, EventArgs e) { FolderBrowserDialog dlg = new FolderBrowserDialog(); if (dlg.ShowDialog() == DialogResult.OK) { textBox1.Text = dlg.SelectedPath; } } private void button4_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "Backup files(*.bak)|*.bak|All Files(*.*)|*.*"; dlg.FilterIndex = 0; if (dlg.ShowDialog() == DialogResult.OK) { textBox3.Text = dlg.FileName; } } private void button3_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=email_client;Integrated Security=True"); con.Open(); try { sql = "alter database email_client set single_user with rollback immediate ;"; sql += "RESTORE database email_client from disk='"+textBox3.Text+"'with replace;"; cmd = new SqlCommand(sql, con); cmd.ExecuteNonQuery(); con.Close(); con.Dispose(); MessageBox.Show("done"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void Backup_Load(object sender, EventArgs e) { } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)