Backup of Remote SQL Server using VB Net Code

Discussion in 'Microsoft VB .NET' started by MikeTI, Jan 26, 2010.

  1. MikeTI

    MikeTI Guest

    Jan 26, 2010

    Hi all

    I am using VB Net 2008 and SQL 2008.

    I am taking a backup of a local SQL Server Database using the following
    code:

    Dim backup As SQLDMO.Backup = New SQLDMO.BackupClass()
    Dim sqlserver As SQLDMO.SQLServer = New SQLDMO.SQLServerClass()
    sqlserver.LoginSecure = False
    sqlserver.Connect("MIKETI-PC\sqlexpress", "sa", "sapassword")
    backup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database
    backup.Database = "TestDataBase"

    backup.Files = "C:\SQL_BACKUP\TestDataBase.bak"
    backup.BackupSetName = "Test01"
    backup.BackupSetDescription = "Database backup description"
    backup.Initialize = True
    backup.SQLBackup(sqlserver)

    How can I take a backup of a remote SQL Server Database on my local PC ??

    Regards
    Mike TI
     
    MikeTI, Jan 26, 2010
    #1
    1. Advertisements

  2. MikeTI

    Joe Cool Guest

    On Jan 26, 6:21 am, "MikeTI" <> wrote:
    > Jan 26, 2010
    >
    > Hi all
    >
    > I am using VB Net 2008 and SQL 2008.
    >
    > I am taking a backup of a local SQL Server Database using the following
    > code:
    >
    >         Dim backup As SQLDMO.Backup = New SQLDMO.BackupClass()
    >         Dim sqlserver As SQLDMO.SQLServer = New SQLDMO.SQLServerClass()
    >         sqlserver.LoginSecure = False
    >         sqlserver.Connect("MIKETI-PC\sqlexpress", "sa", "sapassword")
    >         backup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database
    >         backup.Database = "TestDataBase"
    >
    >         backup.Files = "C:\SQL_BACKUP\TestDataBase.bak"
    >         backup.BackupSetName = "Test01"
    >         backup.BackupSetDescription = "Database backup description"
    >         backup.Initialize = True
    >         backup.SQLBackup(sqlserver)
    >
    > How can I take a backup of a remote SQL Server Database on my local PC ??
    >


    Use a standard SqlClient connection and execute a backup database
    transact-sql command. It is my impression that you will only be able
    to make a backup copy to a local disk, but you can make a backup to
    network disk if SQL instance service is running under a domain/
    workgroup account instead of the server's local SYSTEM account.

    http://msdn.microsoft.com/en-us/library/ms186865.aspx
     
    Joe Cool, Jan 26, 2010
    #2
    1. Advertisements

  3. MikeTI

    Rich P Guest

    If you are working remotely, I think you can only run the backup
    operation on the machine (the remote server) where the DB resides. Then
    you can copy/FTP the .bak to your local computer. I think.

    Rich

    *** Sent via Developersdex http://www.developersdex.com ***
     
    Rich P, Jan 26, 2010
    #3
  4. MikeTI

    eliza Guest

    Backup SQL Database Through Code In VB.NET

    Using the SQL SMO object we can easily take backup of SQL database through code.To find the codes plz check th link below:

    http://www.mindfiresolutions.com/Backup-SQL-Database-Through-Code-In-VBNET-846.php



    MikeTI wrote:

    Backup of Remote SQL Server using VB Net Code
    26-Jan-10

    Jan 26, 201

    Hi al

    I am using VB Net 2008 and SQL 2008

    I am taking a backup of a local SQL Server Database using the followin
    code

    Dim backup As SQLDMO.Backup = New SQLDMO.BackupClass(
    Dim sqlserver As SQLDMO.SQLServer = New SQLDMO.SQLServerClass(
    sqlserver.LoginSecure = Fals
    sqlserver.Connect("MIKETI-PC\sqlexpress", "sa", "sapassword"
    backup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Databas
    backup.Database = "TestDataBase

    backup.Files = "C:\SQL_BACKUP\TestDataBase.bak
    backup.BackupSetName = "Test01
    backup.BackupSetDescription = "Database backup description
    backup.Initialize = Tru
    backup.SQLBackup(sqlserver

    How can I take a backup of a remote SQL Server Database on my local PC ?

    Regard
    Mike TI

    Previous Posts In This Thread:

    On Tuesday, January 26, 2010 6:21 AM
    MikeTI wrote:

    Backup of Remote SQL Server using VB Net Code
    Jan 26, 201

    Hi al

    I am using VB Net 2008 and SQL 2008

    I am taking a backup of a local SQL Server Database using the followin
    code

    Dim backup As SQLDMO.Backup = New SQLDMO.BackupClass(
    Dim sqlserver As SQLDMO.SQLServer = New SQLDMO.SQLServerClass(
    sqlserver.LoginSecure = Fals
    sqlserver.Connect("MIKETI-PC\sqlexpress", "sa", "sapassword"
    backup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Databas
    backup.Database = "TestDataBase

    backup.Files = "C:\SQL_BACKUP\TestDataBase.bak
    backup.BackupSetName = "Test01
    backup.BackupSetDescription = "Database backup description
    backup.Initialize = Tru
    backup.SQLBackup(sqlserver

    How can I take a backup of a remote SQL Server Database on my local PC ?

    Regard
    Mike TI

    On Tuesday, January 26, 2010 12:14 PM
    Joe Cool wrote:

    rClass()rd")Databaseion"Use a standard SqlClient connection and execute a
    rClass(
    rd"
    Databas
    ion

    Use a standard SqlClient connection and execute a backup databas
    transact-sql command. It is my impression that you will only be abl
    to make a backup copy to a local disk, but you can make a backup t
    network disk if SQL instance service is running under a domain
    workgroup account instead of the server's local SYSTEM account

    http://msdn.microsoft.com/en-us/library/ms186865.aspx

    On Tuesday, January 26, 2010 3:11 PM
    Rich P wrote:

    If you are working remotely, I think you can only run the backupoperation on
    If you are working remotely, I think you can only run the backu
    operation on the machine (the remote server) where the DB resides. The
    you can copy/FTP the .bak to your local computer. I think

    Ric

    *** Sent via Developersdex http://www.developersdex.com ***


    Submitted via EggHeadCafe - Software Developer Portal of Choice
    Get Started with SQLite and Visual Studio
    http://www.eggheadcafe.com/tutorial...b-b6f46d4f2c6a/get-started-with-sqlite-a.aspx
     
    eliza, Mar 17, 2010
    #4
  5. MikeTI

    CaptianMalek

    Joined:
    Sep 21, 2012
    Messages:
    2
    Likes Received:
    0
    Hey sir

    hmmm use this

    [FONT=&quot]'--imports the tools [/FONT][FONT=&quot][/FONT]​
    [FONT=&quot]
    Imports Microsoft.SqlServer.Management.Smo
    Imports Microsoft.SqlServer.Management.Common[/FONT]
    [FONT=&quot][/FONT]​
    [FONT=&quot] [/FONT][FONT=&quot][/FONT]​
    [FONT=&quot]'--here you are Declare the object of backup
    [/FONT]
    [FONT=&quot]
    Dim WithEvents oBackup As New Backup[/FONT]
    [FONT=&quot][/FONT]​
    [FONT=&quot] [/FONT]

    [FONT=&quot][/FONT][FONT=&quot][/FONT]​
    [FONT=&quot]
    Private Sub BackupSqlDatabase()[/FONT]
    [FONT=&quot][/FONT]​
    [FONT=&quot] [/FONT][FONT=&quot][/FONT]​
    [FONT=&quot]Dim conn As New ServerConnection(serverName, userName, passWd) '[/FONT][FONT=&quot] -- set SQL server connection given the server name, user name and password[/FONT][FONT=&quot]
    Dim oSQLServer As New Server(conn) [/FONT]
    [FONT=&quot]'--create the SMO server object using connection[/FONT][FONT=&quot][/FONT]​
    [FONT=&quot] [/FONT][FONT=&quot][/FONT]​
    [FONT=&quot]Dim OrigBackupPath As String = oSQLServer.Information.MasterDBPath.Replace("\DATA", "\Backup\DB_BACKUP_NAME.BAK") ' -- set the path where backup file will be stored[/FONT][FONT=&quot][/FONT]​
    [FONT=&quot] [/FONT][FONT=&quot][/FONT]​
    [FONT=&quot]Dim bkDevItem As New BackupDeviceItem(OrigBackupPath, DeviceType.File) [/FONT][FONT=&quot]' -- create SMO.Backupdevice object[/FONT][FONT=&quot][/FONT]​
    [FONT=&quot] [/FONT][FONT=&quot][/FONT]​
    [FONT=&quot]With oBackup ' Set the backup object property
    .Action = BackupActionType.Database
    .Database = YOUR_DATABASE_NAME
    .Devices.Add(bkDevItem)
    .Initialize = True
    .Checksum = True
    .ContinueAfterError = True
    .Incremental = False
    .LogTruncation = BackupTruncateLogType.Truncate
    .SqlBackup(oSQLServer) ' backup SQL database
    End With[/FONT]
    [FONT=&quot][/FONT][FONT=&quot] [/FONT][FONT=&quot][/FONT]​
    [FONT=&quot]End Sub[/FONT][FONT=&quot][/FONT]​

    my regards to you :)
     
    CaptianMalek, Sep 22, 2012
    #5
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lori
    Replies:
    11
    Views:
    304
    One Handed Man [ OHM ]
    Sep 11, 2003
  2. Stanley Sin

    How can I remote access SQL server 2000 using vb.net

    Stanley Sin, Mar 28, 2006, in forum: Microsoft VB .NET
    Replies:
    0
    Views:
    197
    Stanley Sin
    Mar 28, 2006
  3. mrmagoo
    Replies:
    5
    Views:
    451
    Jim Hughes
    Mar 29, 2006
  4. DR
    Replies:
    0
    Views:
    456
  5. Martin Racette
    Replies:
    4
    Views:
    686
    Martin Racette
    May 1, 2008
Loading...

Share This Page