?? db_back_restore.cs
字號:
?using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace Elysian
{
public class DB_back_restore
{
//備份
public static void Back(string str,string filePath)
{
string strconn = DataSource.GetConnectionString();
SqlConnection sqlconn = new SqlConnection(strconn);
SqlCommand sqlcomm = new SqlCommand("backup database '" + str + "' to disk='" + filePath + "' ", sqlconn);
sqlcomm.CommandType = CommandType.Text;
try
{
sqlconn.Open();
sqlcomm.ExecuteNonQuery();
sqlconn.Close();
MessageBox.Show("備份成功!");
}
catch (Exception ex)
{
//throw (ex);
MessageBox.Show("備份失敗!",ex.ToString());
}
}
//還原
public static void restore(string str, string filePath)
{
string strconn = DataSource.GetConnectionString();
SqlConnection sqlconn = new SqlConnection(strconn);
SqlCommand sqlcomm = new SqlCommand("restore database '" + str + "' from disk='" + filePath + "' ", sqlconn);
sqlcomm.CommandType = CommandType.Text;
try
{
sqlconn.Open();
sqlcomm.ExecuteNonQuery();
sqlconn.Close();
MessageBox.Show("備份還原成功!");
}
catch (Exception ex)
{
//throw (ex);
MessageBox.Show("備份還原失敗!",ex.ToString());
}
}
}
}
/* BACKUP DATABASE Northwind
TO DISK = 'c:\Northwind.bak'
RESTORE FILELISTONLY
FROM DISK = 'c:\Northwind.bak'
RESTORE DATABASE TestDB
FROM DISK = 'c:\Northwind.bak'
WITH MOVE 'Northwind' TO 'c:\test\testdb.mdf',
MOVE 'Northwind_log' TO 'c:\test\testdb.ldf'
*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -