HOME > .NET Framework > Forum > ไม่ยอม RESTORE ให้ครับช่วยดูให้ทีครับๆๆ.RESTORE cannot process database 'Healths' because it is in use by this session..
ไม่ยอม RESTORE ให้ครับช่วยดูให้ทีครับๆๆ.RESTORE cannot process database 'Healths' because it is in use by this session..
Dim strSQL As String
Dim strCon As String
strCon = "Data Source=OPLEZAJA-PC;Initial Catalog=Healths;Integrated Security=True"
Dim cmdRestore As SqlClient.SqlCommand = New SqlClient.SqlCommand
Using conn As SqlConnection = New SqlConnection(strCon)
conn.Open()
cmdRestore.Connection = conn
Cursor = Cursors.WaitCursor
Try
strSQL = "ALTER DATABASE Healths SET SINGLE_USER"
cmdRestore.CommandText = strSQL
cmdRestore.ExecuteNonQuery()
strSQL = "RESTORE DATABASE Healths "
strSQL &= "FROM DISK = 'D:\Healths.bak' "
strSQL &= "WITH Replace "
cmdRestore.Connection = conn
cmdRestore.CommandText = strSQL
cmdRestore.ExecuteNonQuery()
MsgBox("ทำการ Restore ข้อมูลเสร็จสินแล้ว.")
Catch ex As Exception
MsgBox("ไม่สามารถทำการ Restore ข้อมูลได้ Restore Error.")
Finally
strSQL = "ALTER DATABASE Healths SET MULTI_USER"
cmdRestore.CommandText = strSQL
cmdRestore.ExecuteNonQuery()
End Try
Cursor = Cursors.Arrow
conn.Close()
cmdRestore.Dispose()
cmdRestore = Nothing
End Using
End Sub
ขึ้น Erorr ว่า RESTORE cannot process database 'Healths' because it is in use by this session. It is recommended that the master database be used when performing this operation. RESTORE DATABASE is terminating abnormally.