Hello, i created a program in Visual Basic 2012 with Internal database ( Service Based Database)- which im going to use as a Local database, i deployed it and installed in a client PC,now he wants me to make some changes in the program, but doesnt wants to lose the data he inserted in the program.
How can i backup and restore the data or how can i Update the Program with the changes i made.
ps. i installed : SQL Expres and SQL Local DB in clients pc
Loading
Gaurav ManusmarePosted Mar 10, 2014, 8:53 AM
Jasmin MPosted Mar 6, 2014, 2:07 PM
it says this message :
Database 'TEST' does not exist. Make sure that the name is entered correctly. Backup Database is terminating abnormally.
I put the right name in the codes but i dont know why cant i backup it (i think it might be that i use an internal local database). Pls help me solve this
Gaurav ManusmarePosted Mar 6, 2014, 8:39 AM
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=your_database_name;Integrated Security=True");
con.Open();
try
{
SqlCommand cmd = new SqlCommand("backup database email_client to disk ='" + path+ "\\" + name_you_want_to_give_to_database + ".bak'", con);
cmd.ExecuteNonQuery();
MessageBox.Show("done");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Div
For Restore
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=master;Integrated Security=True");
con.Open();
try
{
sql = "alter database your_database_name set single_user with rollback immediate ;";
sql += "RESTORE database your_database_name from disk='"+backup_file_name+"'with replace;";
cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
con.Close();
con.Dispose();
MessageBox.Show("done");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}