Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '------------------------------------------------------------------------------------------
- ' Notice of My Copyright and Intellectual Property Rights
- '
- ' Any intellectual property contained within the program by Joseph L. Bolen remains the
- ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
- ' publish or provide such intellectual property to any other person or entity for any
- ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
- '
- ' Copyright © 2015. All rights reserved.
- ' All trademarks remain the property of their respective owners.
- '-------------------------------------------------------------------------------------------
- ' Program Name: Backup Database Demo
- '
- ' Author: Joseph L. Bolen
- ' Date Created: June 2015
- '
- ' Description: Simple Database Backup Demo, backing up the Payables Database.
- '
- ' Documentation is at:
- ' App's Visual Basic .NET code is at http://pastebin.com/u/jaybeeoh
- ' Video tutorials at YouTube: http://www.youtube.com/user/bolenpresents
- '-------------------------------------------------------------------------------------------
- Imports System.Data.SqlClient
- Public Class BackupDBForm
- Private Sub BackupDBButton_Click(sender As Object, e As EventArgs) Handles BackupDBButton.Click
- Dim TargetPathFile As String = "U:\My Backups\Payables_" & DateTime.Today.ToString("yyyy-MM-dd") & ".bak"
- Dim ConnStr As String = "Data Source=.\SQLEXPRESS;Initial Catalog=Payables;Integrated Security=True"
- Dim sqlQuery As String = "BACKUP DATABASE Payables TO DISK = @TargetPathFile;"
- Using con As New SqlConnection(ConnStr)
- Dim cmd As New SqlCommand(sqlQuery, con)
- cmd.Parameters.AddWithValue("@TargetPathFile", TargetPathFile)
- Try
- con.Open()
- Dim sqlReturnValue As Integer = cmd.ExecuteNonQuery
- con.Close()
- If sqlReturnValue <> -1 Then
- MessageBox.Show("SQL Response value was: " & sqlReturnValue.ToString(),
- "SQL Response",
- MessageBoxButtons.OK,
- MessageBoxIcon.Information)
- Else
- MessageBox.Show("DataBase Payables has been backed up to to disk successfully.",
- "DB Backup Completed",
- MessageBoxButtons.OK,
- MessageBoxIcon.Information)
- End If
- Catch ex As SqlException
- MessageBox.Show("SQL Server error # " & ex.Number & ": " & ex.Message,
- ex.GetType.ToString,
- MessageBoxButtons.OK,
- MessageBoxIcon.Error)
- End Try
- End Using
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment