Here is a procedure is use for back up in C#.Hope it helps
public void PerformBackUp(string BackUpLocation, string BackUpFileName, string DatabaseName, string ServerName)
{
DatabaseName = "[" + DatabaseName + "]";
string fileUNQ = DateTime.Now.Day.ToString() + "_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year.ToString() +"_"+ DateTime.Now.Hour.ToString()+ DateTime.Now .Minute .ToString () + "_" + DateTime .Now .Second .ToString () ;
BackUpFileName = BackUpFileName + fileUNQ + ".bak";
string SQLBackUp = @"BACKUP DATABASE " + DatabaseName + " TO DISK = N'" + BackUpLocation + @"\" + BackUpFileName + @"'";
string svr = "Server=" + ServerName + ";Database=master;Integrated Security=True";
SqlConnection cnBk = new SqlConnection(svr);
SqlCommand cmdBkUp = new SqlCommand(SQLBackUp, cnBk);
try
{
cnBk.Open();
cmdBkUp.ExecuteNonQuery();
string msg = "Database " + DatabaseName + " successfully backed up to " + BackUpLocation + @"\" + BackUpFileName
+ "\n Back Up Date : " + DateTime.Now.ToString();
MessageBox .Show(msg,Application .ProductName , MessageBoxButtons .OK, MessageBoxIcon .Information );
lblProgress.Visible = false;
progressBar1.Visible = false;
}
catch (Exception ex)
{
MessageBox.Show("Database " + DatabaseName + "back up error.\n" + ex.Message, "Back Up Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
finally
{
if (cnBk.State == ConnectionState.Open)
{
cnBk .Close();
}
}
}