Hi,
I'm trying to get some progress feedback from the following (Restore DB using SMO):
Sub DoRestore()
Dim svr As Server = New Server("Server\SQL2008")
Dim res As Restore = New Restore()
res.Devices.AddDevice("C:\MyDB.bak", DeviceType.File)
res.Database = "MyDB"
res.RelocateFiles.Add(New RelocateFile("MyDB_Data", "C:\MyDB.mdf"))
res.RelocateFiles.Add(New RelocateFile("MyDB_Log", "C:\MyDB.ldf"))
res.PercentCompleteNotification = 1
AddHandler res.PercentComplete, AddressOf ProgressEventHandler
res.SqlRestoreAsync(svr)
End Sub
Private Sub ProgressEventHandler(ByVal sender As Object, ByVal e As PercentCompleteEventArgs)
ProgressBar.Value = e.Percent
End Sub
This errors stating that the ProgressBar cannot be accessed from a thread it was not created on.
If I use res.SqlRestore it works but the UI is unresponsive.
I've tried to setup another event handler to pass the completion percentage back to the UI thread but not too sure what I'm doing here...
Private Sub ProgressEventHandler(ByVal sender As Object, ByVal e As PercentCompleteEventArgs)
AddHandler e.Percent, AddressOf UpdateProgressBar
End Sub
Private Sub UpdateProgressBar(ByVal sender As Object, ByVal e As PercentCompleteEventArgs)
ProgressBar.Value = e.Percent
End Sub
I get "Percent is not an even of SMO.PercentCompleteEventArgs"