' Create a database backup.
Public Sub CreateBackup( _
ByVal connectionString As String, _
ByVal backupPath As String) _
Implements Microsoft.Web.Management.DatabaseManager.IDbBackupManager.CreateBackup
' Create a connection to the database.
Dim connection As OleDbConnection = New OleDbConnection(connectionString)
Try
' Verify that the source database path is not the same as the backup path.
If connection.DataSource.Equals(backupPath, StringComparison.OrdinalIgnoreCase) Then
' Raise an exception that the database file paths cannot match.
Throw New ArgumentException("The database backup path cannot match the source path.")
Else
' Copy the database file to the backup path.
File.Copy(connection.DataSource, backupPath, True)
End If
Catch ex As Exception
' Raise an exception if an error occurs.
Throw New ProviderException(ex.Message)
Finally
' Close the database connection.
connection.Close()
End Try
End Sub