Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB7
Expertise: Intermediate
Mar 17, 2003

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 Try

Sub 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 Try
End Sub
Marco Bellinaso
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap