在此特别感谢zsgzsgzsg(zsg) ( ) 的帮助!

xksboth 2003-03-31 07:54:31
问题解决了!

真的很感谢zsgzsgzsg(zsg) ( )





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

dim sn As New ADODB.Recordset
cn.Open "Provider=SQLOLEDB.1;server=123;Persist Security Info=False;Initial Catalog=master;Data Source=127.0.0.1;user id=sa;password=7"
sn.Open "select spid from sysprocesses where dbid=db_id( 'student1')", cn
Do While Not sn.EOF
cn.Execute "kill " & sn("spid")
sn.MoveNext
Loop
sn.Close
s_restore = "restore database student1 from disk='" + Trim(Text1.Text) + "' with REPLACE"
cn.Execute s_restore
cn.BeginTrans
If Err.Number = 0 Then
cn.CommitTrans
MsgBox "数据恢复成功!", vbInformation, "提示"
Command1.Enabled = True
Label1.Visible = False
Else
cn.RollbackTrans
MsgBox "数据恢复失败!", vbCritical, "提示"
Command1.Enabled = True
End If
cn.Close
Set cn = Nothing
Me.MousePointer = 1
Else
Exit Sub
End If
On Error Resume Next
Dim DBC As New DataBaseConnection
If db.State = 1 Then
db.Close
End If
db.ConnectionString = DBC.SqlConnectString(d1, d2, d3)
rs.CursorType = adOpenDynamic
rs.CursorLocation = adUseClient
rs.LockType = adLockOptimistic
db.CursorLocation = adUseClient
db.Open
Set cmd.ActiveConnection = db
If Err.Number Then
MsgBox Err.Description, 16 + vbOKOnly, Err.Number
Exit Sub
End If
db.DefaultDatabase = "student1"
If Err.Number Then
MsgBox Err.Description, 16 + vbOKOnly, Err.Number
Exit Sub
End If
End If


以上代码为我的程序恢复数据库的全过程!

具体思想是先断开所有与数据库当前建立的连接!

然后再恢复数据库

再连接上数据库

思想和代码有点麻烦!

但还是实现了!

这得多谢zsgzsgzsg(zsg) ( )

再次感谢你!


...全文
25 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
xksboth 2003-04-03
各位都到全了!

感谢你们!

结贴!
回复
chenyu5188 2003-04-02
GX

UP
回复
_131_ 2003-04-02
解决就好,今后偶有什么不懂的地方,还希望大家多指点,谢谢!!!!!
回复
zhenxizhou 2003-04-01
good
回复
xks 2003-04-01
CSDN就是好心人多嘛!
回复
zsgzsgzsg 2003-04-01
不客气!!祝贺你成功!!
回复
WuYunpeng 2003-03-31
回复
相关推荐
发帖

1187

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2003-03-31 07:54
社区公告
暂无公告