IDbBackupManager..::.CreateBackup Method
.NET Framework Class Library
IDbBackupManager..::.CreateBackup Method

Creates a database backup.

Namespace:  Microsoft.Web.Management.DatabaseManager
Assembly:  Microsoft.Web.Management.DatabaseManager (in Microsoft.Web.Management.DatabaseManager.dll)
Syntax

'Usage

Dim instance As IDbBackupManager
Dim connectionString As String
Dim backupPath As String

instance.CreateBackup(connectionString, _
    backupPath)

'Declaration

Sub CreateBackup ( _
    connectionString As String, _
    backupPath As String _
)

Parameters

connectionString
Type: System..::.String
The connection string for the database.
backupPath
Type: System..::.String
The path of the backup to create.
Remarks

All implementations of the IDbBackupManager interface must also implement the CreateBackup method, which the database manager will use to create database backups.

Examples

The following code sample implements the CreateBackup method for an OLEDB connection that uses the connection string and backup path that the database manager provides.


    ' 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



Permissions

  • Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see .
See Also

Reference

© 2010 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View