title: SQL Server backup&restore
body: <p><strong>backup</strong></p>
  
  <pre><code>string connectionString1 = (@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Database1.mdf;Database=Database1;Integrated Security=True; User Instance=True");
              SqlConnection cn = new SqlConnection(connectionString1);
              cn.Open();
              SqlCommand cmd = new SqlCommand();
              SqlDataReader reader;
              cmd.CommandText = @"BACKUP DATABASE Database1 TO DISK = 'C:\SRI2Works.bak'";
  
              cmd.CommandType = CommandType.Text;
              cmd.Connection = cn;
              reader = cmd.ExecuteReader();
              cn.Close();
              MessageBox.Show("Database Backup Successfull.");
  </code></pre>
  
  <p><strong>restore</strong></p>
  
  <pre><code>string connectionString1 = (@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Database1.mdf;Database=Database1;Integrated Security=True; User Instance=True");
              SqlConnection cn = new SqlConnection(connectionString1);
              cn.Open();
  
              SqlCommand cmd = new SqlCommand();
              SqlDataReader reader;
              cmd.CommandText = @"use master; RESTORE DATABASE Database1 FROM DISK = 'C:\SRI2Works.bak'";
              cmd.CommandText = "DBCC CHECKDB ('Database1')";
              cmd.CommandType = CommandType.Text;
              cmd.Connection = cn;
              reader = cmd.ExecuteReader();
              cn.Close();
              MessageBox.Show("Database Restored Successfull.");
  </code></pre>
  
  <p>This code runs successfully but doesn't make any changes.</p>