Imports System.Data.SqlClient
Public Class Form1
Dim database As String = My.Application.Info.DirectoryPath.ToString & "\YouTubeDB.mdf"
Dim databaselog As String = My.Application.Info.DirectoryPath.ToString & "\YouTubeDB_log.ldf"
Dim con As SqlConnection = New SqlConnection("Data Source=(LocalDB)\v11.0;Integrated Security=True;Connect Timeout=30")
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.BringToFront()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'Restore
OpenFileDialog1.InitialDirectory = My.Application.Info.DirectoryPath.ToString
OpenFileDialog1.ShowDialog()
Dim restorecommand As String = "Use [Master]; Restore Database [" & database & "] from Disk ='" & OpenFileDialog1.FileName & "' with File = 1, Move 'YouTubeDB' to '" & database & "' , Move 'YouTubeDB_log' to '" & databaselog & "', Replace"
Dim cmd As SqlCommand = New SqlCommand(restorecommand, con)
Try
con.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
Finally
con.Close()
con.Dispose()
End Try
Shell(My.Application.Info.DirectoryPath.ToString & "\YouTubeDB.exe", AppWinStyle.NormalFocus)
Me.Close()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Backup
Dim stempel As String = (Date.Today.Day.ToString & "-" & Date.Today.Month.ToString & "-" & Date.Today.Year.ToString & " " & Date.Now.Hour.ToString & "-" & Date.Now.Minute.ToString & "-" & Date.Now.Second.ToString & " Uhr")
Dim backup_name As String = stempel
Dim backupcommand As String = "backup database [" & database & "] to Disk ='" & My.Application.Info.DirectoryPath.ToString & "\YouTubeDB " & stempel & ".bak'"
Dim cmd As SqlCommand = New SqlCommand(backupcommand, con)
Try
con.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
Finally
con.Close()
con.Dispose()
End Try
If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath.ToString & "\YouTubeDB " & backup_name & ".bak") Then
Shell(My.Application.Info.DirectoryPath.ToString & "\YouTubeDB.exe")
Me.Close()
Else
MsgBox("Fehler Backup! Nicht erfolgreicht.")
Shell(My.Application.Info.DirectoryPath.ToString & "\YouTubeDB.exe")
Me.Close()
End If
End Sub
End Class
Public Class Form1
Private Sub TableBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TableBindingNavigatorSaveItem.Click
Me.Validate()
Me.TableBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.YouTubeDBDataSet)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.BringToFront()
'TODO: Diese Codezeile lädt Daten in die Tabelle "YouTubeDBDataSet.Table". Sie können sie bei Bedarf verschieben oder entfernen.
Me.TableTableAdapter.Fill(Me.YouTubeDBDataSet.Table)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Shell(My.Application.Info.DirectoryPath.ToString & "\YouTubeBackup.exe", AppWinStyle.NormalFocus)
Me.Close()
End Sub
End Class