1
using System;
2
using System.Data;
3
using System.Configuration;
4
using System.Collections;
5
using System.Web;
6
using System.Web.Security;
7
using System.Web.UI;
8
using System.Web.UI.WebControls;
9
using System.Web.UI.WebControls.WebParts;
10
using System.Web.UI.HtmlControls;
11
12
public partial class databasemanager : System.Web.UI.Page
13
{
14
protected void Page_Load(object sender, EventArgs e)
15
{
16
17
}
18
19
///
<
summary
>
20
/// 数据库恢复和备份
21
///
</
summary
>
22
23
#region SQL数据库备份
24
///
<
summary
>
25
/// SQL数据库备份
26
///
</
summary
>
27
///
<
param
name
="ServerIP"
>
SQL服务器IP或(Localhost)
</
param
>
28
///
<
param
name
="LoginName"
>
数据库登录名
</
param
>
29
///
<
param
name
="LoginPass"
>
数据库登录密码
</
param
>
30
///
<
param
name
="DBName"
>
数据库名
</
param
>
31
///
<
param
name
="BackPath"
>
备份到的路径
</
param
>
32
public static void SQLBACK(string ServerIP, string LoginName, string LoginPass, string DBName, string BackPath)
33
{
34
SQLDMO.Backup oBackup = new SQLDMO.BackupClass();
35
SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
36
try
37
{
38
oSQLServer.LoginSecure = false;
39
oSQLServer.Connect(ServerIP, LoginName, LoginPass);
40
oBackup.Database = DBName;
41
oBackup.Files = BackPath;
42
oBackup.BackupSetName = DBName;
43
oBackup.BackupSetDescription = "数据库备份";
44
oBackup.Initialize = true;
45
oBackup.SQLBackup(oSQLServer);
46
}
47
catch (Exception e)
48
{
49
throw new Exception(e.ToString());
50
}
51
finally
52
{
53
oSQLServer.DisConnect();
54
}
55
}
56
#endregion
57
#region SQL恢复数据库
58
///
<
summary
>
59
/// SQL恢复数据库
60
///
</
summary
>
61
///
<
param
name
="ServerIP"
>
SQL服务器IP或(Localhost)
</
param
>
62
///
<
param
name
="LoginName"
>
数据库登录名
</
param
>
63
///
<
param
name
="LoginPass"
>
数据库登录密码
</
param
>
64
///
<
param
name
="DBName"
>
要还原的数据库名
</
param
>
65
///
<
param
name
="BackPath"
>
数据库备份的路径
</
param
>
66
public static void SQLDbRestore(string ServerIP, string LoginName, string LoginPass, string DBName, string BackPath)
67
{
68
69
SQLDMO.Restore orestore = new SQLDMO.RestoreClass();
70
SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
71
try
72
{
73
oSQLServer.LoginSecure = false;
74
oSQLServer.Connect(ServerIP,LoginName,LoginPass);
75
orestore.Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
76
orestore.Database = DBName;
77
orestore.Files = BackPath;
78
orestore.FileNumber = 1;
79
orestore.ReplaceDatabase = true;
80
orestore.SQLRestore(oSQLServer);
81
}
82
catch (Exception e)
83
{
84
throw new Exception(e.ToString());
85
}
86
finally
87
{
88
oSQLServer.DisConnect();
89
}
90
}
91
92
#endregion
93
94
protected void Button_back_Click(object sender, EventArgs e)
95
{
96
try
97
{
98
SQLBACK(serverIP.Text, servername.Text, serverpwd.Text, databasename.Text, databasepath.Text);
99
Response.Write("数据库备份成功!");
100
}
101
catch (Exception exp)
102
{
103
Response.Write("数据库备份失败!"+exp.Message);
104
}
105
}
106
protected void Button_go_Click(object sender, EventArgs e)
107
{
108
try
109
{
110
SQLDbRestore(serverIP.Text, servername.Text, serverpwd.Text, databasename.Text, databasepath.Text);
111
Response.Write("数据库还原成功!");
112
}
113
catch (Exception exp)
114
{
115
116
Response.Write("数据库还原失败!"+exp.Message);;
117
}
118
}
119
}
120
相关文章
- 傻瓜式实战Oracle 10g RMAN之数据库备份和恢复
- xtrabackup进行MySQL数据库备份/还原
- Xtrabackup数据库的数据备份和还原
- SQL Server数据库的备份和还原(留着慢慢看)
- 备份和还原 Linux 上的 SQL Server 数据库
- 将Sql Server 2005数据库备份还原到Sql Server 2000
- mysql数据库全备和全备还原(使用Xtrabackup)
- 在SQL查询分析器中,如何设置命令将已备份的数据强制还原到指定的数据库?
- 怎么在SQL2000里面添加从别的地方备份过来的数据啊,附加数据库的时候它提示不是正确的MDF文件
- java对mysql数据库进行单表筛选备份、还原操作