Backup Database using C#

This tutorial about, taking a backup of the sql server database.
 
Following sql query, we can get a backup:

backup database database_name to disk='d:\aaa.bak' 
 
To implement this backup in windows application. 
  1. using (SqlConnection con = new SqlConnection(connectionstring))  
  2. {  
  3.      con.Open();  
  4.      query = "backup database databasename to disk ='" + path + ""
  5.              +System.DateTime.Now.Month+System.DateTime.Now.Date.ToString("dd")+System.DateTime.Now.Year+".bak'";  

  6.      using( SqlCommand cmd=new SqlCommand(query,con))  
  7.      {  
  8.           cmd.ExecuteNonQuery();    

  9.           MessageBox.Show("Saved successfully""Backup", MessageBoxButtons.OK, MessageBoxIcon.Information);  
  10.    
  11.      }  
  12.      
  13. }