Regarding backup in database in visual studio [Resolved]

Posted by Dklpu under ASP.NET on 12/14/2015 | Points: 10 | Views : 338 | Status : [Member] | Replies : 3
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();


}





Responses

Posted by: Lucygrey on: 12/16/2015 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi,
The best way to backup your database by using SQL Server Management Studio, that must be installed on your SQl Server.

Helpful links:-
https://msdn.microsoft.com/en-us/library/ms187048.aspx
http://stackoverflow.com/questions/15867613/backing-up-database-in-visual-studio-c-sharp

http://www.keenesystems.com/Services/SoftwareDevelopment.aspx

Dklpu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 12/14/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
Please check if the SQL Server instance has been pointed correctly or not in the connection string and if so then check if the database is present or not in that instance.
Hope this helps

--
Thanks & Regards,
RNA Team

Dklpu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dklpu on: 12/15/2015 [Member] Starter | Points: 25

Up
0
Down
Connectionstring with DB is fine but cannot link with database name

Dklpu, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response