I have to backup my database in visual studio , I used local database but on writting th following code it gives error
Database 'dk' does not exist. Make sure that the name is entered correctly. BACKUP DATABASE is terminating abnormally.
code in button event is
string connew = ConfigurationManager.ConnectionStrings["ConnectionString2"].ConnectionString;
SqlConnection sqlcon = new SqlConnection(connew);
sqlcon.Open();
string destdir = "F:\\backup";
if (!System.IO.Directory.Exists(destdir))
{
System.IO.Directory.CreateDirectory("F:\\backup");
}
try
{
SqlCommand sqlcmd = new SqlCommand("backup database dk to disk='" + destdir + "\\" + DateTime.Now.ToString("ddMMyyyy_HHmmss") + ".Bak'", sqlcon);
sqlcmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
Label3.Text = "Succesfullycreated backup";
sqlcon.Close();
}