harryagustiana Administrator
Jumlah posting : 212 Reputasi : 11 Join date : 04.12.10 Age : 33 Lokasi : Bandung, Indonesia
| Subyek: Cara backup dan restore SQL Database file melalui VB.Net Sun Nov 06, 2011 8:09 pm | |
| Silahkan pelajari syntaxnya dibawah ini : - Code:
-
Imports System.Data.SqlClient Public Class FrmBackup Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If TextBox3.Text = "" Then MsgBox("Isi Database", MsgBoxStyle.Critical) ElseIf TextBox1.Text = "" Then MsgBox("Silahkan cari tempat penyimpanan", MsgBoxStyle.Critical) Else MulaiBackup() End If End Sub Private Sub MulaiBackup() Try cmd1 = New SqlCommand("BACKUP DATABASE " & TextBox3.Text & " TO DISK = N'" & TextBox1.Text & "' WITH NOFORMAT, NOINIT, NAME = N'gudang_6309249-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10", con1) cmd1.ExecuteNonQuery() cmd1.Dispose() MsgBox("Backup sukses", MsgBoxStyle.Information) Catch ex As Exception MsgBox("Backup gagal", MsgBoxStyle.Critical) MsgBox(ex.Message) End Try
End Sub
Private Sub MulaiRestore() Try cmd1 = New SqlCommand("RESTORE DATABASE " & TextBox3.Text & " FROM DISK = N'" & TextBox2.Text & "' WITH FILE = 1, NOUNLOAD, STATS = 10", con1) cmd1.ExecuteNonQuery() cmd1.Dispose() MsgBox("restore sukses", MsgBoxStyle.Information) Catch ex As Exception MsgBox("restore gagal", MsgBoxStyle.Critical) MsgBox(ex.Message) End Try End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim fdlg As SaveFileDialog = New SaveFileDialog() fdlg.Title = "Simpan Backup File(Bak FIle)" fdlg.InitialDirectory = "c:" fdlg.Filter = "All files (*.*)|*.*|BAK FIle (*.bak*)|*.bak" fdlg.FilterIndex = 2 fdlg.RestoreDirectory = True If fdlg.ShowDialog() = DialogResult.OK Then TextBox1.Text = fdlg.FileName End If End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If TextBox3.Text = "" Then MsgBox("Isi Database", MsgBoxStyle.Critical) ElseIf TextBox2.Text = "" Then MsgBox("Silahkan cari file backup", MsgBoxStyle.Critical) Else MulaiRestore() End If End Sub
Private Sub FrmBackup_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load koneksi1() End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim fdlg As OpenFileDialog = New OpenFileDialog() fdlg.Title = "Cari Backup File(Bak FIle)" fdlg.InitialDirectory = "c:" fdlg.Filter = "All files (*.*)|*.*|BAK FIle (*.bak*)|*.bak*" fdlg.FilterIndex = 2 fdlg.RestoreDirectory = True If fdlg.ShowDialog() = DialogResult.OK Then TextBox2.Text = fdlg.FileName End If End Sub End Class Contoh form : |
|
harryagustiana Administrator
Jumlah posting : 212 Reputasi : 11 Join date : 04.12.10 Age : 33 Lokasi : Bandung, Indonesia
| Subyek: Re: Cara backup dan restore SQL Database file melalui VB.Net Sun Nov 06, 2011 8:11 pm | |
| MySQL : Backup dan Restore syntax di form : - Code:
-
For Backup....
Process.Start("C:\MySQL\MySQL Server 5.1\bin\mysqldump.exe", "-u username -p***** existing_database -r C:\backup.sql")
For Restore....
Dim myProcess As New Process()
myProcess.StartInfo.FileName = "cmd.exe"
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.WorkingDirectory = "C:\MySQL\MySQL Server 5.1\bin"
myProcess.StartInfo.RedirectStandardInput = True
myProcess.StartInfo.RedirectStandardOutput = True
myProcess.Start()
Dim myStreamWriter As StreamWriter = myProcess.StandardInput
Dim mystreamreader As StreamReader = myProcess.StandardOutput
myStreamWriter.WriteLine("mysql -u username -p***** databasename < C:\backup.sql ")
myStreamWriter.Close()
myProcess.WaitForExit()
myProcess.Close()
|
|