用VB如何备份和还原SQL Server数据库????

cjwcyc 2003-01-20 04:33:58
用VB如何备份和还原SQL Server数据库????
...全文
49 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xks 2003-03-25
  • 打赏
  • 举报
回复
Dim cn As New ADODB.Connection
Dim s_path, s_dataexport As String
s_path = App.path
Me.MousePointer = 11
s_dataexport = "backup database database_name to disk='" + s_path + "\backup\" + Format(Now(), "YY-MM-DD") + userinfo.Depname + "backup.dat'"
cn.Open gs_conn_string
cn.BeginTrans
cn.Execute s_dataexport
Err.Number = 0
If Err.Number = 0 Then
cn.CommitTrans
MsgBox "数据备份成功!", vbInformation, "提示"
Else
cn.RollbackTrans
MsgBox "数据备份失败!", vbCritical, "提示"
End If
cn.Close
Set cn = Nothing
Me.MousePointer = 1


Dim ret As Integer
If Text1.Text = "" Then
MsgBox "请选择要恢复的数据文件!", vbInformation, "提示"
Exit Sub
Else
ret = MsgBox("数据恢复操作将会覆盖以前的所有数据并且覆盖后无法恢复,您确定要进行恢复操作吗?", vbQuestion + vbOKCancel + "提示")
If ret = vbOK Then
Me.MousePointer = 11
Dim cn As New ADODB.Connection
Dim s_restore As String
'Debug.Print gs_conn_string
'此时需要连接master数据库才能完成数据恢复操作
cn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=7;Initial Catalog=master;Data Source=127.0.0.1 "
'同上student1为需要恢复的数据库
s_restore = "restore database student1 from disk='" + Trim(Text1.Text) + "'"
'text1一个用于记录需要恢复文件的地址的textbox
cn.Execute s_restore
cn.BeginTrans
If Err.Number = 0 Then
cn.CommitTrans
MsgBox "数据恢复成功!", vbInformation, "提示"
Else
cn.RollbackTrans
MsgBox "数据恢复失败!", vbCritical, "提示"
End If
cn.Close
Set cn = Nothing
Me.MousePointer = 1
Else
Exit Sub
End If
End If
jiang_nan 2003-01-20
  • 打赏
  • 举报
回复
建议备份文件的文件名带上当时的系统日期:db & format("yyyy-mm-dd",date) & "-" & format("hh-mm-ss",time)
nik_Amis 2003-01-20
  • 打赏
  • 举报
回复
sSQL = "RESTORE DATABASE " & sDatabaseName & " FROM DISK=" & Wrap(sDatabaseFile) & " WITH REPLACE "
sSQL = "BACKUP DATABASE " & sDatabaseName & " TO DISK=" & Wrap(sDatabaseFile) & " WITH INIT"

maoqingfeng 2003-01-20
  • 打赏
  • 举报
回复
用 backup restore sql语句
antshome 2003-01-20
  • 打赏
  • 举报
回复
强烈建议参考SQLDMO的例子,在SQL 2000安装盘里DEVTOOLS\SAMPLES\目录下

7,785

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧