Restoring database with SMO - Reporting progress problems

Posted by madlan on Stack Overflow See other posts from Stack Overflow or by madlan
Published on 2010-06-06T13:37:48Z Indexed on 2010/06/06 13:42 UTC
Read the original article Hit count: 332

Filed under:
|
|
|

I'm using the below to restore a database in VB.NET. This works but causes the interface to lockup if the user clicks anything. Also, I cannot get the progress label to update incrementally, it's blank until the backup is complete then displays 100%

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.SqlRestore(svr)
End Sub

Private Sub ProgressEventHandler(ByVal sender As Object, ByVal e As PercentCompleteEventArgs)
    Label3.Text = ""
    ProgressBar.Value = e.Percent
    LblProgress.Text = e.Percent.ToString
End Sub

© Stack Overflow or respective owner

Related posts about sql

Related posts about vb.net