private void btnRestore_Click(object sender, RoutedEventArgs e) { if (String.IsNullOrEmpty(txtRestorePath.Text)) { System.Windows.MessageBox.Show("请选择还原路径"); return; } try { using (var visaORM = new visaEntities()) { string sql = @"use master RESTORE DATABASE [QZ] FROM DISK = N'" + txtRestorePath.Text + "' WITH FILE = 1, NOUNLOAD , STATS = 10, RECOVERY , REPLACE "; int rowCount = visaORM.ExecuteStoreCommand(sql); } System.Windows.Forms.MessageBox.Show("数据还原成功"); } catch (Exception err) { Log.WriteLog.WriteErorrLog(err); System.Windows.Forms.MessageBox.Show(err.Message); } }
private void btnBackup_Click(object sender, RoutedEventArgs e) { if (String.IsNullOrEmpty(txtBackupPath.Text)) { System.Windows.MessageBox.Show("请选择备份路径"); return; } try { using (var visaORM = new visaEntities()) { string sql = @"BACKUP DATABASE [visa] TO DISK = N'" + txtBackupPath.Text + "' WITH NOINIT , NOUNLOAD , NAME = N'Visa Back', NOSKIP , STATS = 10, NOFORMAT "; int rowCount = visaORM.ExecuteStoreCommand(sql); } System.Windows.Forms.MessageBox.Show("备份成功"); } catch (Exception err) { Log.WriteLog.WriteErorrLog(err); System.Windows.Forms.MessageBox.Show(err.Message); } }