Here is my code for to back up a database.
This are my databases:
I got this as Error:
Database 'BakupDB' does not exist. Make sure that the name is entered correctly.BACKUP DATABASE is terminating abnormally.\[code\]public partial class Default2 : System.Web.UI.Page{ string dbname = "BakupDB"; SqlConnection sqlcon = new SqlConnection(); SqlCommand sqlcmd = new SqlCommand(); SqlDataAdapter da = new SqlDataAdapter(); DataTable dt = new DataTable(); protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click1(object sender, EventArgs e) { //Mentioned Connection string make sure that user id and password sufficient previlages sqlcon.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\BakupDB.mdf;Integrated Security=True;User Instance=True"; //Enter destination directory where backup file stored string destdir = "D:\\backupdb"; try { sqlcon.Open(); sqlcmd = new SqlCommand("backup database "+dbname+" to disk='" + destdir + "\\" + DateTime.Now.ToString("ddMMyyyy_HHmmss") + ".Bak'", sqlcon); sqlcmd.ExecuteNonQuery(); sqlcon.Close(); Response.Write("Backup database successfully"); } catch (Exception ex) { Response.Write("Error During backup database!"); } }}\[/code\]What do I wrong?
This are my databases:
Database 'BakupDB' does not exist. Make sure that the name is entered correctly.BACKUP DATABASE is terminating abnormally.\[code\]public partial class Default2 : System.Web.UI.Page{ string dbname = "BakupDB"; SqlConnection sqlcon = new SqlConnection(); SqlCommand sqlcmd = new SqlCommand(); SqlDataAdapter da = new SqlDataAdapter(); DataTable dt = new DataTable(); protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click1(object sender, EventArgs e) { //Mentioned Connection string make sure that user id and password sufficient previlages sqlcon.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\BakupDB.mdf;Integrated Security=True;User Instance=True"; //Enter destination directory where backup file stored string destdir = "D:\\backupdb"; try { sqlcon.Open(); sqlcmd = new SqlCommand("backup database "+dbname+" to disk='" + destdir + "\\" + DateTime.Now.ToString("ddMMyyyy_HHmmss") + ".Bak'", sqlcon); sqlcmd.ExecuteNonQuery(); sqlcon.Close(); Response.Write("Backup database successfully"); } catch (Exception ex) { Response.Write("Error During backup database!"); } }}\[/code\]What do I wrong?