Hi Everyone
I made a program for restore database from vb.net. but my code not correctly.the error show
RESTORE cannot process database 'trydb' 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.
This is my code:
Dim openfiledialog As New OpenFileDialog
Dim restore As String
restore = Path.GetDirectoryName(OpenFileDialog1.FileName) + "\" + Path.GetFileName(OpenFileDialog1.FileName)
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
cmd = New SqlCommand("restore database [DRRM_Student_Database] from DISK ='" & restore & "' ", conn)
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
MsgBox("restore success")
End If