c#.net 数据库备份还原
vs2005C#.NET+SQLEXPRESS2005怎样设计一个页面,来备份还原App_Data下的数据库文件?具体应该怎么写啊?SQL不太懂哎...
vs2005 C#.NET + SQLEXPRESS 2005
怎样设计一个页面,来备份还原App_Data下的数据库文件?
具体应该怎么写啊?SQL不太懂哎 展开
怎样设计一个页面,来备份还原App_Data下的数据库文件?
具体应该怎么写啊?SQL不太懂哎 展开
4个回答
展开全部
在C#的某事件中执行sql备份语句
完整备份
Backup Database NorthwindCS
To disk=’G:\Backup\NorthwindCS_Full_20070908.bak’
--差异备份
Backup Database NorthwindCS
To disk=’G:\Backup\NorthwindCS_Diff_20070908.bak’
With Differential
--日志备份,默认截断日志
Backup Log NorthwindCS
To disk=’G:\Backup\NorthwindCS_Log_20070908.bak’
--日志备份,不截断日志
Backup Log NorthwindCS
To disk=’G:\Backup\NorthwindCS_Log_20070908.bak’
With No_Truncate
--截断日志不保留
Backup Log NorthwindCS
With No_Log
--或者
Backup Log NorthwindCS
With Truncate_Only
--截断之后日志文件不会变小
--有必要可以进行收缩
--文件备份
Exec Sp_Helpdb NorthwindCS --查看数据文件
Backup Database NorthwindCS
File=’NorthwindCS’ --数据文件的逻辑名
To disk=’G:\Backup\NorthwindCS_File_20070908.bak’
--备份设置密码保护备份
Backup Database NorthwindCS
To disk=’G:\Backup\NorthwindCS_Full_20070908.bak’
With Password = ’123’,init
Restore Database NorthwindCS
From disk=’G:\Backup\NorthwindCS_Full_20070908.bak’
With Password = ’123’
private void button1_Click(object sender, EventArgs e)
{
try
{
string backupFolder = System.IO.Path.Combine(Application.StartupPath, "data");
if (!System.IO.Directory.Exists(backupFolder))//判断文件夹是否存在
{
//创建文件夹
System.IO.Directory.CreateDirectory(backupFolder);
}
string backupFileName = System.IO.Path.Combine(backupFolder, DateTime.Today.ToString("yyyyMMdd.bak"));
string sqltxt = string.Format("BACKUP DATABASE [FOOT] TO DISK='{0}'", backupFileName);
SqlConnection conn = baseclass.DBConn.cycon();
conn.Open();
SqlCommand cmd = new SqlCommand(sqltxt, conn);
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("备份成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
this.Close();
}
完整备份
Backup Database NorthwindCS
To disk=’G:\Backup\NorthwindCS_Full_20070908.bak’
--差异备份
Backup Database NorthwindCS
To disk=’G:\Backup\NorthwindCS_Diff_20070908.bak’
With Differential
--日志备份,默认截断日志
Backup Log NorthwindCS
To disk=’G:\Backup\NorthwindCS_Log_20070908.bak’
--日志备份,不截断日志
Backup Log NorthwindCS
To disk=’G:\Backup\NorthwindCS_Log_20070908.bak’
With No_Truncate
--截断日志不保留
Backup Log NorthwindCS
With No_Log
--或者
Backup Log NorthwindCS
With Truncate_Only
--截断之后日志文件不会变小
--有必要可以进行收缩
--文件备份
Exec Sp_Helpdb NorthwindCS --查看数据文件
Backup Database NorthwindCS
File=’NorthwindCS’ --数据文件的逻辑名
To disk=’G:\Backup\NorthwindCS_File_20070908.bak’
--备份设置密码保护备份
Backup Database NorthwindCS
To disk=’G:\Backup\NorthwindCS_Full_20070908.bak’
With Password = ’123’,init
Restore Database NorthwindCS
From disk=’G:\Backup\NorthwindCS_Full_20070908.bak’
With Password = ’123’
private void button1_Click(object sender, EventArgs e)
{
try
{
string backupFolder = System.IO.Path.Combine(Application.StartupPath, "data");
if (!System.IO.Directory.Exists(backupFolder))//判断文件夹是否存在
{
//创建文件夹
System.IO.Directory.CreateDirectory(backupFolder);
}
string backupFileName = System.IO.Path.Combine(backupFolder, DateTime.Today.ToString("yyyyMMdd.bak"));
string sqltxt = string.Format("BACKUP DATABASE [FOOT] TO DISK='{0}'", backupFileName);
SqlConnection conn = baseclass.DBConn.cycon();
conn.Open();
SqlCommand cmd = new SqlCommand(sqltxt, conn);
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("备份成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
this.Close();
}
展开全部
简单的做法就不用SQL。
直接用.NET自带的IO来备份APP_DATA下的文件即可。
直接用.NET自带的IO来备份APP_DATA下的文件即可。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
调用SQL语句实行数据库备份,
1楼回答很好
1楼回答很好
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我这有例子要不要
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |