Could not locate entry in sysdatabases for database 'abcd'. No entry found with that name. Make sure that the name is entered correctly. BACKUP DATABASE is terminating abnormally.
string dbname = "abcd"; SqlConnection sqlcon = new SqlConnection(); SqlCommand sqlcmd = new SqlCommand(); SqlDataAdapter da = new SqlDataAdapter(); DataTable dt = new DataTable(); protected void btn_Click(object sender, EventArgs e) { //Mentioned Connection string make sure that user id and password sufficient previlages sqlcon.ConnectionString= @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\abcd.mdf ;Integrated Security=True;User Instance=True"; //Enter destination directory where backup file stored string destdir = "D:\\Backup"; //Check that directory already there otherwise create if (!System.IO.Directory.Exists(destdir)) { System.IO.Directory.CreateDirectory("D:\\Backup"); } // try { //Open connection sqlcon.Open(); //query to take backup database sqlcmd = new SqlCommand("backup database " + dbname + " to disk='" + destdir + "\\" + DateTime.Now.ToString("ddMMyyyy_HHmmss") + ".Bak'", sqlcon); sqlcmd.ExecuteNonQuery(); //Close connection sqlcon.Close(); Response.Write("Backup database successfully"); } // catch (Exception ex) { Response.Write("Error During backup database!"); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)