How to restore sql database
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
October 9th, 2011 12:15am
Witwew,
When creating your conn object, in the connection string, specify the master database as the initial database. Don't have a session open to the trydb while you are backing it up.
So you'll want a connection string similiar to this:
Data Source=SQLServer1;Initial Catalog=master;User ID=sa;Password=***********
Tom Overton
Free Windows Admin Tool Kit Click here and download it now
October 9th, 2011 12:19am


