Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to 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 3-May-13 20:12pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
 
Imports System.Data.SqlClient
Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Management.Common
 
Then code something like this:
 
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
 

 

  Permalink  
Comments
Priyanka Jain at 4-May-13 1:40am
   
i didnot find these references. plz tell me from where i can get these reference?
Richard.Berry100 at 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\
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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

  Print Answers RSS
0 OriginalGriff 6,569
1 Sergey Alexandrovich Kryukov 6,168
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 4 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100