Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try Dim con2 As SqlConnection Dim cmd2 As SqlCommand Dim Filename2 As String '= Integer.Parse(s.Remove(0, 3)) 'Dim s As String = "" Dim strQuery2 As String Dim database2 As String Dim get_servername2 As String 'get the value selected in Database Name dropdon menu/ combobox database2 = cmbdatabase.Text get_servername2 = cmbservername.Text.Trim 'get selected value of Server Name dropdown menu
Dim opendlg As New OpenFileDialog Dim constr2 As String
'open SQL database to restore If opendlg.ShowDialog = DialogResult.OK Then 'netframwork 4.5.x windows.forms. Cursor = Cursors.WaitCursor con2 = New SqlConnection(constr2) 'get/set connection data source con2.Open() 'open connection
Dim dbCommmand As New SqlCommand(constr, con) ' 03.09.2019 ??????? dbCommmand.CommandTimeout = 6000 ' 03.09.2019 ?????? 1,6h
Filename2 = opendlg.FileName ' -= (Integer.Parse(s.Remove(0, 3))) geht nicht! - get the file name and path of the SQL database selected strQuery2 = "Restore database " & database2 & " from disk='" & Filename2 & "'" '#### entfernen ! right(path, len(path) - 9) & ! & Format(Today(),"MMddyyyy")
'execute command Try cmd2 = New SqlCommand(strQuery2, con2) cmd2.CommandTimeout = 6000 ' #### oder hier setzen das timout ?????? 03.09.2019 ???????? cmd2.ExecuteNonQuery() MessageBox.Show("Database " & database2 & " Wurde erfolgreich wiederhergestellt.", "Nachricht", MessageBoxButtons.OK, MessageBoxIcon.Information) con2.Close() con2.Dispose() '### TM 30.10.2017 - Fehler: Exclusive access could not be obtained because the database is in use. Restore Database is terminating abnormally - Resourcen Freigeben!!!! Cursor = Cursors.Default Catch ex As Exception Cursor = Cursors.Default MessageBox.Show(ex.Message, "Nachricht", MessageBoxButtons.OK, MessageBoxIcon.Information) End Try 'con2.Close() '### 17.04.2019 'con2.Dispose() End If Catch ex As Exception Cursor = Cursors.Default MessageBox.Show(ex.Message, "Nachricht", MessageBoxButtons.OK, MessageBoxIcon.Information) End Try 'con2.Close() '### 17.04.2019 'con2.Dispose()