In my last Code snippet i place the code how we can take database backup programatically, this code snippet will show how to restore database
public void Restore(string ServerName, string Login, string Password) { try {
//create an instance of a server class SQLDMO._SQLServer srv = new SQLDMO.SQLServerClass(); //connect to the server srv.Connect(ServerName, Login, Password); //create a restore class instance SQLDMO.Restore res = new SQLDMO.RestoreClass(); //set the backup device = files property ( easy way ) res.Devices = res.Files; //set the files property to the File Name text box res.Files = "c:\\Fides-Backup.bak"; //set the database to the chosen database res.Database = "ReplicTest"; // Restore the database res.ReplaceDatabase = true; res.SQLRestore(srv); //MessageBox.Show("Database restored successfully.", "Restore Successful");
} catch (Exception err) {
//MessageBox.Show(err.Message, "Error"); } } [\code]
ReplicTest is the database name where database will restore c:\\Fides-Backup.bak is a path where your database file is exist Add SQLDMO reference in you application to make the code usable
|
No responses found. Be the first to respond and make money from revenue sharing program.
|