none
How to do Backup and restore using User Session on VB .Net? RRS feed

  • Question

  • Guys,,

    I have a project,,, i have trouble doing backup & restore using User Session,,,

    How to do Backup and restore using User Session on vb .Net?


    • Edited by ibra90 Monday, September 9, 2019 9:50 AM
    Monday, September 9, 2019 9:49 AM

All replies

  • Guys,,

    I have a project,,, i have trouble doing backup & restore using User Session,,,

    How to do Backup and restore using User Session on vb .Net?


    Hi,

    You must feed us about your database type you use or you want to Backup,

    If it's  MS-Access or SQL server 


    Regards From Egypt

    Monday, September 9, 2019 12:16 PM
  • Hi,

    This is an example of backup and recovery of SQL database in VB.net.

    First use master.

    Then alter database dbname set of fline with rollback immediate.

    Then backup the task log.

    Then restore the database.

    Finally, alter database dbname set online with rollback immediate.

    Imports System.Data.SqlClient
    
    Public Class Form1
        Dim conn As SqlConnection
        Dim cmd As SqlCommand
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Using conn = New SqlConnection("Data Source = (localdb)\MSSQLLocalDB; Integrated Security = True ;Initial Catalog=master;Connection Timeout=30;")
                conn.Open()
                cmd = New SqlCommand("ALTER DATABASE [Students] SET ONLINE WITH ROLLBACK IMMEDIATE BACKUP DATABASE Students TO DISK='D:\Local Database\Students1.bak' WITH   Format", conn)
                cmd.ExecuteNonQuery()
                MsgBox("Backup DataBase Successful!")
            End Using
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Using conn = New SqlConnection("Data Source = (localdb)\MSSQLLocalDB; Integrated Security = True ;Initial Catalog=master;Connection Timeout=30;")
                conn.Open()
                cmd = New SqlCommand("ALTER DATABASE [Students] SET OFFLINE WITH ROLLBACK IMMEDIATE RESTORE DATABASE Students FROM DISK = 'D:\Local Database\Students1.bak' WITH REPLACE, STATS = 10", conn)
                cmd.ExecuteNonQuery()
                cmd = New SqlCommand("ALTER DATABASE [Students] SET ONLINE WITH ROLLBACK IMMEDIATE", conn)
                cmd.ExecuteNonQuery()
                MsgBox("Restore DataBase Successful!")
            End Using
        End Sub
    End Class
    

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 10, 2019 5:47 AM