devxlogo

BackupDatabase – Backing-up a SQL Server database

BackupDatabase – Backing-up a SQL Server database

' Backup the specified database.' Note: requires Imports System.Data.SqlClient'' Example:'   Dim connString As String = "server=(local); user id=sa; password=; ' Database=master;"'   Try'      BackupDatabase(connString, "MyTestDB", "D:MyTestDbBackup.bak")'   Catch ex As Exception'      MessageBox.Show(ex.Message)'   End TrySub BackupDatabase(ByVal connString As String, ByVal dbName As String, _    ByVal backupFile As String)    Dim cn As New SqlConnection(connString)    Try        ' the command for backing up the DB        Dim cmdBackup As New SqlCommand("BACKUP DATABASE [" & dbName & _            "] TO DISK = '" & backupFile & "'", cn)        cn.Open()        cmdBackup.ExecuteNonQuery()    Finally        cn.Close()    End TryEnd Sub

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist