How to backup database SQL SERVER from VB NET?
Imports System.Data.SqlClient
Public Class Form1
Dim con As SqlConnection
Dim cmd As SqlCommand
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.Load
con = New SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=DBNAME")
End Sub
' Backup
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click
cmd = New SqlCommand("backup database DBNAME to disk='\\server\path\filename.bak'", con)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Sub
' Restore
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button2.Click
cmd = New SqlCommand("restore database DBNAME from disk='\\server\path\filename.bak'", con)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Sub
End Class
0 comments:
Post a Comment