Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
how to make backup of sql server 2005 data through vb.net so that client side user can easily create own data backup. plz help me..its very urgent...
Posted

You can use SMO

Add these references:

'//***** Add these references**********
'//Microsoft.SqlServer.Smo
'//Microsoft.SqlServer.SmoExtended
'//Microsoft.SqlServer.Management.Sdk.Sfc
'//Microsoft.SqlServer.ConnectionInfo


Add these Imports:

VB
Imports System.Data.SqlClient
Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Management.Common


Then code something like this:

VB
Private Sub Backup
Dim srv As Server
Dim conn As ServerConnection
Dim sqlSErverInstance As String = "YourServerInstanceName"
Dim fileName As String = "MyBackup.bak"
Dim databaseName As String = "MyDatabase"

conn = New ServerConnection(sqlSErverInstance, "Username", "Password")
srv = New Server(conn)
Dim bkp As New Backup()
Try
            

            bkp.Action = BackupActionType.Database
            bkp.Database = databaseName
            bkp.Devices.AddDevice(fileName, DeviceType.File)
            bkp.Incremental = False
            

            bkp.PercentCompleteNotification = 10
            AddHandler bkp.PercentComplete, AddressOf ProgressEventHandler


            bkp.SqlBackup(srv)
            MessageBox.Show("Database Backed Up To: " & fileName, "Backup")

        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        Finally
            Me.ProgressBar1.Value = 0
        End Try

End Sub

 Public Sub ProgressEventHandler(sender As Object, e As PercentCompleteEventArgs)
        Me.ProgressBar1.Value = e.Percent
 End Sub
 
Share this answer
 
Comments
Priyanka Jain 4-May-13 1:40am    
i didnot find these references. plz tell me from where i can get these reference?
Richard.Berry100 4-May-13 12:42pm    
X86 Package (SharedManagementObjects.msi) http://go.microsoft.com/fwlink/?LinkID=188438&clcid=0x409

or

X64 Package (SharedManagementObjects.msi) http://go.microsoft.com/fwlink/?LinkID=188439&clcid=0x409

You can also try browsing to the actual dll - On my machine its:
C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900