Backup and Recovery with windows application with sql server2005

Last post 07-06-2009 6:49 AM by ixtli. 3 replies.

Sort Posts:

  • Backup and Recovery with windows application with sql server2005

    07-02-2009, 2:24 AM
    • Contributor
      2,324 point Contributor
    • susain
    • Member since 10-29-2007, 11:51 AM
    • Hyderabad, Andhra Pradesh, India
    • Posts 646

    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

    Linked In: http://www.linkedin.com/in/mohammedfarooq123

    Mark as answer if this post help full to you.
  • Re: Backup and Recovery with windows application with sql server2005

    07-02-2009, 8:00 AM
    • All-Star
      24,755 point All-Star
    • qwe123kids
    • Member since 03-27-2008, 5:49 AM
    • Mumbai
    • Posts 4,226

    Hi,

    Check the link mention below..

    http://www.geekpedia.com/tutorial180_Backup-and-restore-SQL-databases.html


    Thanks
    Avinash Tiwari

    Remember to click “Mark as Answer” on the post, if it helps you.

    MY Blog

    Hacking Inside .net exe
  • Re: Backup and Recovery with windows application with sql server2005

    07-03-2009, 12:13 AM
    • Contributor
      2,324 point Contributor
    • susain
    • Member since 10-29-2007, 11:51 AM
    • Hyderabad, Andhra Pradesh, India
    • Posts 646

    Thanks Avinash Cool

    The link you have supplied, I had already practiced in vb.net.

    Can you please clarify my above points?

     

    Thanks,

    Farooq

    Linked In: http://www.linkedin.com/in/mohammedfarooq123

    Mark as answer if this post help full to you.
  • Re: Backup and Recovery with windows application with sql server2005

    07-06-2009, 6:49 AM
    Answer
Page 1 of 1 (4 items)