Explanation:try
{
SQLDMO._SQLServer srv = new SQLDMO.SQLServerClass();
srv.Connect("server","username","password");
SQLDMO.Backup bak = new SQLDMO.BackupClass();
bak.Devices = bak.Files;
string path = txtPath.Text; //Path where the backup should be
created.
path = "[" + path + "]";
bak.Files = path;
bak.Database = "DatabaseName";
bak.SQLBackup(srv);
MessageBox.Show("Database backed up successfully.", "Backup Successfull");
this.Cursor = Cursors.Default;
}
catch(Exception err)
{
this.Cursor = Cursors.Default;
MessageBox.Show(err.Message,"Error");
} |