You can use this code to restore database into SQL server
- Private Sub BtnRestore_Click(sender As Object, e As EventArgs) Handles BtnRestore.Click
- Dim database = CmbDatabase .Text
- Dim ServrnameRestore = CmbServer .Text .Trim
- Dim OpenFile1 As New OpenFileDialog
- Dim Constr As String
- Constr ="Data Source=" & ServrnameRestore &"; Initial Catalog=master; Integrated Security=True"
- 'Open connection
- Dim sqlcon As SqlConnection
- Dim cmd As SqlCommand
- If OpenFile1 .ShowDialog = DialogResult.OK Then
- sqlcon = New SqlConnection(Constr)
- ' OpenFileDialog1.ShowDialog()
- filename_Restore = OpenFile1 .FileName
- Dim StrQuery2 ="Restore Database " & database &" from disk ='" & filename_Restore &"' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 5"
- 'Excute query
- cmd = New SqlCommand (Strquery2 ,sqlcon)
- cmd.ExecuteNonQuery ()
- MessageBox .Show ("Database " & database & " has been restored successfull","Message", MessageBoxButtons .OK, MessageBoxIcon .Information )
- sqlcon.Close ()
- MsgBox ("Cancel",MsgBoxStyle.Information ,"Cancel")
- End If
- Catch ex As Exception
- MessageBox .Show (ex.Message ,"Message", MessageBoxButtons .OK , MessageBoxIcon .Warning )
- End Try
- End sub
Thank you follow Instagram: hassan_hambe
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.