Hi Friends,
I designed windows application to perform backup and recovery.
Need clarification for the below points
1) Is it required to take the backup of the tail log file?
2) In restore can I use Replace (I studied that replace option should be used in rare cases)
Here is my code
'For backup
con = New SqlConnection("Data Source=localhost;Initial Catalog=" & Cmbdb.SelectedItem & ";Integrated Security=True")
cmd = New SqlCommand("backup database " & Cmbdb.SelectedItem & " to disk='e:\backup\" & Cmbdb.SelectedItem & st & ".bak' with INIT", con)
Try
con.Open()
cmd.ExecuteNonQuery()
Catch ex As System.Exception
MsgBox(ex.Message, MsgBoxStyle.Information)
Finally
cmd.Dispose()
con.Dispose()
con.Close()
End Try
con = New SqlConnection("Data Source=localhost;Initial Catalog=master;Integrated Security=True")
cmd = New SqlCommand("backup log " & Cmbdb.SelectedItem & " to disk='e:\backup\" & Cmbdb.SelectedItem & st & "log" & ".bak' WITH INIT", con)
Try
con.Open()
cmd.ExecuteNonQuery()
Catch ex As System.Exception
MsgBox(ex.Message, MsgBoxStyle.Information)
Finally
cmd.Dispose()
con.Dispose()
con.Close()
End Try
'For recovery
con = New SqlConnection("Data Source=localhost;Initial Catalog=master;Integrated Security=True")
cmd = New SqlCommand("restore database " & Cmbdb.SelectedItem & " from disk='" & Dlgrecfiles.FileName & "' with Replace", con)
Try
con.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
Finally
dr.Close()
cmd.Dispose()
con.Dispose()
con.Close()
End Try
Waiting for valuable suggestion, links and examples
Thanks,
Farooq