none
How to backup database SQL SERVER from VB NET?

    Question

  • Hi,

    Kindly need help for "How to backup database SQL SERVER from VB NET?"

    Thanks in advance.
    Wednesday, April 16, 2008 8:46 AM

Answers

  • Hi,

     

    You would need the MS SQL Server 2005 client components (For SQL-DMO Library). I do not think there is anything else needed.

     

     

    HTH,
    Suprotim Agarwal

     

    Saturday, April 19, 2008 7:49 AM
  • Hi,

     

    You could use SQL-DMO. Check a sample over here.

     

    HTH,

    Suprotim Agarwal

    Wednesday, April 16, 2008 9:21 AM
  •  qiux wrote:
    Hi,
    Kindly need help for "How to backup database SQL SERVER from VB NET?"

     

    Hi qiux,

     

    Besides using SQL-DMO as Suprotim said, you also can use SQL commands to backup and restore SQL Server database.

    Code Block

    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 As System.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 As System.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 As System.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

    Please check this thread for detail:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2568063&SiteID=1

     

    Regards,

    Martin

    Monday, April 21, 2008 9:49 AM

All replies

  • Hi,

     

    You could use SQL-DMO. Check a sample over here.

     

    HTH,

    Suprotim Agarwal

    Wednesday, April 16, 2008 9:21 AM
  • Thanks, is it required any components which be installed before?
    Thursday, April 17, 2008 2:35 AM
  • Hi,

     

    You would need the MS SQL Server 2005 client components (For SQL-DMO Library). I do not think there is anything else needed.

     

     

    HTH,
    Suprotim Agarwal

     

    Saturday, April 19, 2008 7:49 AM
  •  qiux wrote:
    Hi,
    Kindly need help for "How to backup database SQL SERVER from VB NET?"

     

    Hi qiux,

     

    Besides using SQL-DMO as Suprotim said, you also can use SQL commands to backup and restore SQL Server database.

    Code Block

    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 As System.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 As System.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 As System.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

    Please check this thread for detail:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2568063&SiteID=1

     

    Regards,

    Martin

    Monday, April 21, 2008 9:49 AM
  • Hi Suprotim and Martin,

    Thanks, I got it now.


    Saturday, May 03, 2008 2:20 AM
  • Hi Kindly need help for "How to backup database SQL SERVER from VB NET?" but above code not run. so i need code.

    thanks


    • Proposed as answer by SENTHUJAN Saturday, April 09, 2011 10:47 AM
    • Unproposed as answer by SENTHUJAN Tuesday, April 19, 2011 5:12 AM
    • Proposed as answer by olajidejojo Saturday, October 05, 2013 3:04 PM
    Saturday, April 09, 2011 10:47 AM
  • how to save to client site?.......

    Saturday, June 25, 2011 4:27 AM
  • how to save to client site?.......

    Saturday, June 25, 2011 4:28 AM
  • how to save to client site?.......

    Saturday, June 25, 2011 4:37 AM