با سلام خدمت دوستان.
می خام از DB که در SQLexpress تعریف کردم بکاپ و رستور بنویسم.
بکاپ رو نوشتم ولی رستور رو مشکل دارم.
Public Sub Restore()
Try
Dim op As New Windows.Forms.OpenFileDialog
SqlConnection.ClearAllPools()
op.Filter = "Bak File|*.Bak"
op.InitialDirectory = Application.StartupPath & "\Backup"
If op.ShowDialog() = DialogResult.Cancel Then
Exit Sub
End If
con = New SqlConnection("Data Source=.\SQLEXPRESS;Integrated Security=True;User Instance=True")
con.Open()
Ct = New SqlCommand
Ct.Connection = con
Ct.CommandText = "Restore database [" + Application.StartupPath + "\Bime.mdf] from disk='" + op.FileName + "'"
Ct.ExecuteNonQuery()
con.Close()
MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
اگر برنامه رو اجرا کنم و مستقیم به سراغ رستور برم .رستور انجام میشه ولی اگر در یکی از فرم ها برم و تراکنشی رو انجام بدم و بعد به سراغ رستور برم error میده.
Exclusive access could not be obtained because the database is in use. RESTORE DATABASE is terminating abnormally