Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to take backup of my Local DB in visual studio 2013

i was added some records in my Local DB using with Linq quary

but when i give connection string to Local DB then i got error 'Database not exist'

What I have tried:

private void btbakup_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
SqlCommand sqlcmd = new SqlCommand();

con.ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;";

string backups = "G:\\Backup";
if (!System.IO.Directory.Exists(backups))
{
System.IO.Directory.CreateDirectory(backups);
}

con.Open();

sqlcmd = new SqlCommand("backup database Database1 to disk='" + backups + "\\" + DateTime.Now.ToString("ddMMyyyy_HHmmss") + ".Bak'", con);

sqlcmd.ExecuteNonQuery();
con.Close();

MessageBox.Show("Data Backup Done", "Backup");


}
Posted
Updated 21-Dec-17 22:07pm

This is how I do it: Backing up an SQL Database in C#[^]
 
Share this answer
 
Thanks for reply..

My database is Local database (it mean i was created in .net provider SQL Database in my windows aplication by internal, it not not created in SQL server as External)

as you have given link above that suitable for Extarnal SQL Server
 
Share this answer
 
v3
Comments
Richard Deeming 22-Dec-17 12:42pm    
If you want to reply to a solution, click the "Have a Question or Comment?" button under that solution.

DO NOT post your comment as a new "solution"!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900