数据库的备份和还原代码
来源:互联网 发布:虚拟专用网络端口号 编辑:程序博客网 时间:2024/09/21 08:55
备份:代码如下
string SqlStr1 = "Server=(local);database='" + this.DropDownList1.SelectedValue + "';Uid=sa;Pwd=";
string SqlStr2 = "backup database " + this.DropDownList1.SelectedValue + " to disk='" + this.TextBox1.Text.Trim() + ".bak'";
SqlConnection con = new SqlConnection(SqlStr1);
con.Open();
try
{
if (File.Exists(this.TextBox1.Text.Trim()))
{
Response.Write(" ");
return;
}
SqlCommand com = new SqlCommand(SqlStr2, con);
com.ExecuteNonQuery();
Response.Write(" ");
}
catch (Exception error)
{
Response.Write(error.Message);
Response.Write(" ");
}
finally
{
con.Close();
}
还原数据库代码如下:
string path = this.FileUpload1.PostedFile.FileName; //获得备份路径及数据库名称
string dbname = this.DropDownList1.SelectedValue;
string SqlStr1 = "Server=(local);database='" + this.DropDownList1.SelectedValue + "';Uid=sa;Pwd=";
string SqlStr2 = "use master restore database " + dbname + " from disk='" + path + "'";
SqlConnection con = new SqlConnection(SqlStr1);
con.Open();
try
{
SqlCommand com = new SqlCommand(SqlStr2, con);
com.ExecuteNonQuery();
Response.Write(" ");
}
catch (Exception error)
{
Response.Write(error.Message);
Response.Write(" ");
}
finally
{
con.Close();
}
若要实现自动还原和备份数据库,只需写个定时器定时调用方法即可!
- 数据库的备份和还原代码
- 数据库的备份和还原
- 数据库的备份和还原
- 数据库的备份和还原
- 数据库还原与备份的代码(1)
- PHP备份/还原MySQL数据库的代码
- PHP备份/还原MySQL数据库的代码
- 备份和还原数据库
- 备份和还原数据库
- 数据库备份和还原
- 数据库备份和还原
- 数据库备份和还原
- 数据库备份和还原
- Mysql的数据库的备份和还原
- 还原和备份数据库的脚本
- SQLServer数据库的备份和还原详解
- MySQL数据库备份和还原的常用命令
- MySQL数据库备份和还原的常用命令
- pku2295 A DP Problem
- 网页游戏 1
- 随机数的生成问题??
- ie兼容火狐
- 利用CSS3的新功能实现(椭)圆角边框和图片边框 (圆角)
- 数据库的备份和还原代码
- 使用jxl,Servlet,JSP 动态生成excel文件并提示下载的简单方法
- 元素的尺寸和位置
- 测试数据生成工具TestDataBuilder、DBmonster、dataFactory试用中
- 历史轨迹回放
- do while
- 4.5--如何给一个对话框加入预览区域?
- 弹出UAC窗体,以管理员权限运行程序
- unigine游戏引擎