1.实现数据库的备份:
2.实现数据库恢复:
在恢复时要注意先杀掉当前数据库的所有进程
完整的操作类如下:
在相应的按钮
1
/**/
///
<summary>
2
///
数据库备份
3
///
</summary>
4
///
<returns>
备份是否成功
</returns>
5
public
bool
DbBackup()
6![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
7
string
path
=
CreatePath();
8
SQLDMO.Backup oBackup
=
new
SQLDMO.BackupClass();
9
SQLDMO.SQLServer oSQLServer
=
new
SQLDMO.SQLServerClass();
10
try
11![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
12
oSQLServer.LoginSecure
=
false
;
13
oSQLServer.Connect(server,uid, pwd);
14
oBackup.Action
=
SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
15
oBackup.Database
=
database;
16
oBackup.Files
=
path;
17
oBackup.BackupSetName
=
database;
18
oBackup.BackupSetDescription
=
"
数据库备份
"
;
19
oBackup.Initialize
=
true
;
20
oBackup.SQLBackup(oSQLServer);
21![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
22
return
true
;
23
}
24
catch
(Exception ex)
25![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
26
return
false
;
27
throw
ex;
28
}
29
finally
30![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
31
oSQLServer.DisConnect();
32
}
33
}
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
2
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
3
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
5
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
7
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
12
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
16
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
20
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
22
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
23
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
24
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
26
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
28
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
29
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
30
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
31
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
32
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
33
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
2.实现数据库恢复:
在恢复时要注意先杀掉当前数据库的所有进程
1
/**/
///
<summary>
2
///
数据库恢复
3
///
</summary>
4
public
string
DbRestore()
5![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
6
if
(exepro()
!=
true
)
//
执行存储过程
7![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
8
return
"
操作失败
"
;
9
}
10
else
11![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
12
SQLDMO.Restore oRestore
=
new
SQLDMO.RestoreClass();
13
SQLDMO.SQLServer oSQLServer
=
new
SQLDMO.SQLServerClass();
14
try
15![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
16
exepro();
17
oSQLServer.LoginSecure
=
false
;
18
oSQLServer.Connect(server, uid, pwd);
19
oRestore.Action
=
SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
20
oRestore.Database
=
database;
21![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**/
///
自行修改
22
oRestore.Files
=
@"
d:/aaa/aaa.bak
"
;
23
oRestore.FileNumber
=
1
;
24
oRestore.ReplaceDatabase
=
true
;
25
oRestore.SQLRestore(oSQLServer);
26![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
return
"
ok
"
;
28
}
29
catch
(Exception e)
30![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
31
return
"
恢复数据库失败
"
;
32
throw
e;
33
}
34
finally
35![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
36
oSQLServer.DisConnect();
37
}
38
}
39
}
40
41![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**/
///
<summary>
42
///
杀死当前库的所有进程
43
///
</summary>
44
///
<returns></returns>
45
private
bool
exepro()
46![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
47![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
48
SqlConnection conn1
=
new
SqlConnection(
"
server=
"
+
server
+
"
;uid=
"
+
uid
+
"
;pwd=
"
+
pwd
+
"
;database=master
"
);
49
SqlCommand cmd
=
new
SqlCommand(
"
killspid
"
,conn1);
50
cmd.CommandType
=
CommandType.StoredProcedure;
51
cmd.Parameters.Add(
"
@dbname
"
,
"
aaa
"
);
52
try
53![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
54
conn1.Open();
55
cmd.ExecuteNonQuery();
56
return
true
;
57
}
58
catch
(Exception ex)
59![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
60
return
false
;
61
}
62
finally
63![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
64
conn1.Close();
65
}
66
}
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
2
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
3
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
4
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
6
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
8
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
10
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
12
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
16
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
20
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
22
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
23
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
24
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
26
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
28
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
29
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
30
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
31
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
32
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
33
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
34
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
35
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
36
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
37
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
38
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
39
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
40
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
41
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
42
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
43
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
44
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
45
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
46
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
47
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
48
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
49
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
50
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
51
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
52
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
53
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
54
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
55
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
56
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
57
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
58
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
59
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
60
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
61
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
62
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
63
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
64
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
65
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
66
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
完整的操作类如下:
1
using
System;
2
using
System.Collections;
3
using
System.Data;
4
using
System.Data.SqlClient;
5![](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
6
namespace
DbBackUp
7![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
8![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**/
///
<summary>
9
///
创建人:Terrylee
10
///
创建时间:2005年8月1日
11
///
功能描述:实现数据库的备份和还原
12
///
更新记录:
13
///
</summary>
14
public
class
DbOperate
15![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
16![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**/
///
<summary>
17
///
服务器
18
///
</summary>
19
private
string
server;
20
21![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**/
///
<summary>
22
///
登录名
23
///
</summary>
24
private
string
uid;
25
26![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**/
///
<summary>
27
///
登录密码
28
///
</summary>
29
private
string
pwd;
30
31![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**/
///
<summary>
32
///
要操作的数据库
33
///
</summary>
34
private
string
database;
35
36![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**/
///
<summary>
37
///
数据库连接字符串
38
///
</summary>
39
private
string
conn;
40![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
41![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**/
///
<summary>
42
///
DbOperate类的构造函数
43
///
在这里进行字符串的切割,获取服务器,登录名,密码,数据库
44
///
</summary>
45
public
DbOperate()
46![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
47
conn
=
System.Configuration.ConfigurationSettings.AppSettings[
"
constr
"
].ToString();
48
server
=
StringCut(conn,
"
server=
"
,
"
;
"
);
49
uid
=
StringCut(conn,
"
uid=
"
,
"
;
"
);
50
pwd
=
StringCut(conn,
"
pwd=
"
,
"
;
"
);
51
database
=
StringCut(conn,
"
database=
"
,
"
;
"
);
52
}
53
54![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**/
///
<summary>
55
///
切割字符串
56
///
</summary>
57
///
<param name="str"></param>
58
///
<param name="bg"></param>
59
///
<param name="ed"></param>
60
///
<returns></returns>
61
public
string
StringCut(
string
str,
string
bg,
string
ed)
62![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
63
string
sub;
64
sub
=
str.Substring(str.IndexOf(bg)
+
bg.Length);
65
sub
=
sub.Substring(
0
,sub.IndexOf(
"
;
"
));
66
return
sub;
67
}
68
69![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**/
///
<summary>
70
///
构造文件名
71
///
</summary>
72
///
<returns>
文件名
</returns>
73
private
string
CreatePath()
74![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
75
string
CurrTime
=
System.DateTime.Now.ToString();
76
CurrTime
=
CurrTime.Replace(
"
-
"
,
""
);
77
CurrTime
=
CurrTime.Replace(
"
:
"
,
""
);
78
CurrTime
=
CurrTime.Replace(
"
"
,
""
);
79
CurrTime
=
CurrTime.Substring(
0
,
12
);
80
string
path
=
@"
d://aaa//
"
;
81
path
+=
database;
82
path
+=
"
_db_
"
;
83
path
+=
CurrTime;
84
path
+=
"
.BAK
"
;
85
return
path;
86
}
87![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
88![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**/
///
<summary>
89
///
数据库备份
90
///
</summary>
91
///
<returns>
备份是否成功
</returns>
92
public
bool
DbBackup()
93![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
94
string
path
=
CreatePath();
95
SQLDMO.Backup oBackup
=
new
SQLDMO.BackupClass();
96
SQLDMO.SQLServer oSQLServer
=
new
SQLDMO.SQLServerClass();
97
try
98![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
99
oSQLServer.LoginSecure
=
false
;
100
oSQLServer.Connect(server,uid, pwd);
101
oBackup.Action
=
SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
102
oBackup.Database
=
database;
103
oBackup.Files
=
path;
104
oBackup.BackupSetName
=
database;
105
oBackup.BackupSetDescription
=
"
数据库备份
"
;
106
oBackup.Initialize
=
true
;
107
oBackup.SQLBackup(oSQLServer);
108![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
109
return
true
;
110
}
111
catch
(Exception ex)
112![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
113
return
false
;
114
throw
ex;
115
}
116
finally
117![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
118
oSQLServer.DisConnect();
119
}
120
}
121![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
122![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**/
///
<summary>
123
///
数据库恢复
124
///
</summary>
125
public
string
DbRestore()
126![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
127
if
(exepro()
!=
true
)
//
执行存储过程
128![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
129
return
"
操作失败
"
;
130
}
131
else
132![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
133
SQLDMO.Restore oRestore
=
new
SQLDMO.RestoreClass();
134
SQLDMO.SQLServer oSQLServer
=
new
SQLDMO.SQLServerClass();
135
try
136![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
137
exepro();
138
oSQLServer.LoginSecure
=
false
;
139
oSQLServer.Connect(server, uid, pwd);
140
oRestore.Action
=
SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
141
oRestore.Database
=
database;
142![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**/
///
自行修改
143
oRestore.Files
=
@"
d:/aaa/aaa.bak
"
;
144
oRestore.FileNumber
=
1
;
145
oRestore.ReplaceDatabase
=
true
;
146
oRestore.SQLRestore(oSQLServer);
147![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
148
return
"
ok
"
;
149
}
150
catch
(Exception e)
151![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
152
return
"
恢复数据库失败
"
;
153
throw
e;
154
}
155
finally
156![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
157
oSQLServer.DisConnect();
158
}
159
}
160
}
161
162![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**/
///
<summary>
163
///
杀死当前库的所有进程
164
///
</summary>
165
///
<returns></returns>
166
private
bool
exepro()
167![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
168![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
169
SqlConnection conn1
=
new
SqlConnection(
"
server=
"
+
server
+
"
;uid=
"
+
uid
+
"
;pwd=
"
+
pwd
+
"
;database=master
"
);
170
SqlCommand cmd
=
new
SqlCommand(
"
killspid
"
,conn1);
171
cmd.CommandType
=
CommandType.StoredProcedure;
172
cmd.Parameters.Add(
"
@dbname
"
,
"
aaa
"
);
173
try
174![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
175
conn1.Open();
176
cmd.ExecuteNonQuery();
177
return
true
;
178
}
179
catch
(Exception ex)
180![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
181
return
false
;
182
}
183
finally
184![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
185
conn1.Close();
186
}
187
}
188![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
189
}
190![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
191
}
192
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
8
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
9
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
12
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
14
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
16
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
17
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
19
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
20
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
22
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
23
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
24
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
26
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
27
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
28
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
29
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
30
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
31
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
32
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
33
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
34
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
35
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
36
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
37
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
38
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
39
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
40
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
41
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
42
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
43
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
44
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
45
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
46
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
47
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
48
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
49
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
50
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
51
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
52
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
53
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
54
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
55
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
56
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
57
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
58
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
59
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
60
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
61
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
62
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
63
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
64
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
65
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
66
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
67
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
68
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
69
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
70
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
71
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
72
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
73
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
74
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
75
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
76
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
77
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
78
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
79
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
80
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
81
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
82
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
83
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
84
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
85
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
86
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
87
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
88
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
89
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
90
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
91
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
92
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
93
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
94
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
95
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
96
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
97
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
98
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
99
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
100
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
101
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
102
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
103
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
104
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
105
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
106
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
107
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
108
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
109
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
110
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
111
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
112
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
113
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
114
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
115
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
116
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
117
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
118
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
119
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
120
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
121
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
122
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
123
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
124
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
125
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
126
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
127
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
128
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
129
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
130
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
131
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
132
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
133
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
134
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
135
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
136
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
137
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
138
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
139
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
140
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
141
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
142
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
143
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
144
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
145
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
146
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
147
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
148
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
149
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
150
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
151
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
152
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
153
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
154
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
155
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
156
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
157
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
158
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
159
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
160
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
161
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
162
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
163
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
164
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
165
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
166
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
167
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
168
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
169
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
170
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
171
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
172
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
173
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
174
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
175
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
176
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
177
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
178
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
179
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
180
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
181
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
182
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
183
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
184
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
185
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
186
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
187
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
188
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
189
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
190
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
191
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
192
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
在相应的按钮
1
<
asp:Button
id
="wbtn_Backup"
runat
="server"
Width
="60px"
Text
="备 份"
CssClass
="Button"
></
asp:Button
>
单击事件里调用即可:
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
1
/**/
///
<summary>
2
///
备份按钮
3
///
</summary>
4
///
<param name="sender"></param>
5
///
<param name="e"></param>
6
private
void
wbtn_Backup_Click(
object
sender, System.EventArgs e)
7![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
8
DbOperate dbop
=
new
DbOperate();
9
dbop.DbBackup();
10
}
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
2
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
3
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
6
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
8
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](http://terrylee.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)