弄了很久,还是搞不定它.
各位,你你好!我在系统里面做了个备份与恢复的功能,但是运行的时候恢复那里总是出现如图的错误,我怎么看都不懂,请各位高手指点.
恢复部分代码如下:
Private Sub CmdBackup_Click()
Dim S
If Option1.Value = True Then
'备份数据库
S = Dir1.Path & "\" & Date & ".BAK"
If Label1.Caption = S Then
MsgBox "数据备份卡已存在!"
Else
StrCnn.Open "Driver={SQL Server};Server=ADMIN;Database=wlst;Uid=sa;Pwd=123"
'备份SQL Server数据库
sql = "backup DATABASE wlst TO disk='" & S & "'"
StrCnn.Execute (sql) '执行SQL语句
StrCnn.Close
MsgBox "数据库备份成功!"
key = Date & ".BAK"
Set itmX = ListView1.ListItems.Add(, , key, 1)
End If
End If
If Option2.Value = True Then
'恢复指定路径下的数据库
If File1.ListCount <> 0 Then
If Label1.Caption <> "" Then
' StrCnn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=wlst;Data Source=" & Winsock1.LocalHostName
StrCnn.Open "Driver={SQL Server};Server=ADMIN;Database=wlst;Uid=sa;Pwd=123"
'StrCnn.Open
'数据恢复语句
sql = "RESTORE DATABASE wlst from disk='" & Label1.Caption
StrCnn.Execute (sql) '执行SQL语句 (提示这里出错)
StrCnn.Close
MsgBox "数据库恢复成功!"
Else
MsgBox "请选择要恢复的数据备份卡!"
End If
Else
MsgBox "请选择要恢复的数据备份卡!"
End If
End If
End Sub