Private Sub Command2_Click ()
If Text1. Text="" Then
MsgBox "please choose to restore the data files!" VbInformation, "tip"
The Exit Sub
The Else
Ret=MsgBox (" data recovery operations will cover all of the data before and after the cover can't recover, are you sure you want to restore operation?" , vbQuestion + vbOKCancel, "tip")
If ret=vbOK Then
Dim cn As New ADODB. Connection
Dim sn As New ADODB. You
Dim s_restore As String
Me.
MousePointer=11Cn. Open "the Provider=SQLOLEDB. 1; Persist Security Info=False; Server="& amp; D1 & amp; "; Initial Catalog=master; Data Source=127.0.0.1; User id=sa; Password="& amp; D3 & amp; "
"Sn. Open the "select spid from sysprocesses where dbid=db_id ('" & amp; Me.Com bo1. Text & amp; "')", cn
EOF
the Do While Not sn.Cn. The Execute "kill" & amp; Sn (" spid ")
Sn. MoveNext
Loop
Sn. Close
S_restore="restore the database" & amp; Me.Com bo1. Text & amp;='" + "from disk Trim (Text1. Text) +"' with the REPLACE "
Cn. The Execute s_restore
'the Debug. Print gs_conn_string
'at this moment need to connect the master database to complete data recovery operations
'ditto student1 for need to restore the database
S_restore="restore the database" & amp; Me.Com bo1. Text & amp;='" + "from disk Trim (Text1. Text) +"' "
'text1 a need to restore the file for this account address textbox
Cn. The Execute s_restore
Cn. BeginTrans
If Err. Number=0 Then
Cn.Com mitTrans
MsgBox "data recovery success!" VbInformation, "tip"
Command1. Enabled=True
Label1. Visible=False
The Else
Cn. RollbackTrans
MsgBox "data recovery failure!" VbCritical, "tip"
Command1. Enabled=True
End the If
Cn. Close
The Set cn=Nothing
Me. MousePointer=1
The Else
The Exit Sub
End the If ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
On the Error Resume Next
Dim DBC As New Connection
If the db. The State=1 Then
The close
End the If
The db. The ConnectionString=DBC. SqlConnectString (d1, d2, d3)
Rs. The CursorType=adOpenDynamic
Rs. CursorLocation=adUseClient
Rs. LockType=adLockOptimistic
The CursorLocation=adUseClient
The Open
The Set CMD. The ActiveConnection=db
If Err. Number Then
MsgBox Err. Description, 16 + vbOKOnly, Err. Number
The Exit Sub
End the If
The DefaultDatabase="& amp; Me.Com bo1. Text & amp; "
If Err. Number Then
MsgBox Err. Description, 16 + vbOKOnly, Err. Number
The Exit Sub
End the If
End the If
Prompt error is: unable to rewrite the file 'd: \ \ SQL SQL az \ MSSQL \ data \ water_hammer_data MDF' database 'water_hammer' are using this file, please everyone a great god for help to solve!
CodePudding user response:
Collapsed in the pop-up dialog box, press the corresponding button to enter debugging press Alt + 7 key to view the Call Stack from the inside to the following out of from the inner to outer function Call history, double-click a row to the cursor to the Call of the source code or assembly instruction, double-click on the next line when don't understand, until can understand,CodePudding user response:
'the Debug. Print gs_conn_string'needs to connect at this time the master database to complete data recovery operations
Please understand the correct meaning of the sentence annotations
CodePudding user response: